Android 通过资源名称来获取resID的方法: 目的:获取res中一张图片 test.png 的资源Id 方法1: 20200704 测试此方法可用
String string
= "test";
try{
Field field
= R
.drawable
.class.getField(string
);
int resID
= Integer
.parseInt(field
.get(null
).toString());
}catch(Exception e
){
e
.printStackTrace
;
}
imageView
.setBackground(Activity
.getDrawable(resID
));
参考:https://blog.csdn.net/guiping_ding/article/details/50918511