动态获取资源ID——getIdentifier()

作者:追风剑情 发布于:2015-6-19 12:11 分类:Android

在unity中调用引用了资源的java代码时,必须用动态获取资源。

下面是一段测试代码


Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.story_post_test);
KakaoLog.i("R.drawable.story_post_test="+R.drawable.story_post_test);
KakaoLog.i("bitmap="+bitmap);
		
int resID = getResources().getIdentifier("story_post_test", "drawable", getCurrentActivity().getPackageName());
Drawable drawable = getResources().getDrawable(resID);
KakaoLog.i("drawable="+drawable);
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), resID);
KakaoLog.i("R.drawable.story_post_test="+resID);
KakaoLog.i("bitmap1="+bitmap1);


运行结果

resID.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号