我有这样的密码:

String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());

字符串s=指令设置的值与res/drawable hdpi文件夹中的一个名称相同。但是,返回值将rid设置为值0
知道我的代码为什么不能工作吗?我做错什么了吗?

最佳答案

试试这个

String s = "replace__menu__" + data.imageid;  // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());

07-24 15:46