废话不多说,直接上代码:
public static int getDrawableByName(String name){
if (name==null) return -1;
try {
Field field=R.drawable.class.getField(name);
return field.getInt(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return -1;
}
网友评论