我有一个使用 Android 库 (com.appocaliptic.quizknife.core) 的 Android 项目 (com.appocaliptic.quizknife.app)。
我想做的是获取图片的资源ID,即图书馆。图片的路径是:res/drawable-xhdpi/fr_200_133.png
但是,所有尝试都使用 getIdentifier 结果为 0。问题出在哪里?
resId = getResources().getIdentifier("fr_200_133", "drawable", "com.appocaliptic.quizknife.core");
resId = getResources().getIdentifier("com.appocaliptic.quizknife.core:drawable/"+"fr_200_133", null, null);
resId = getResources().getIdentifier("drawable/fr_200_133", null, "com.appocaliptic.quizknife.core");
已编辑:
啊,在R.java中有drawable和corresponding属性。
最佳答案
我遇到了同样的问题:"getIdentifier result 0" 我通过删除图像扩展名(*.jpg、*.jpeg、...等)以匹配名称来解决它在 R.java 文件中
关于Android - getIdentifier 始终返回 0(库 + 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12394688/