Android drawable 反射取资源id
时间:2014-11-26 22:07:23
收藏:0
阅读:292
通过反射来获取资源id
try{
String resName = "ic_launcher";
int resId = R.drawable.class.getDeclaredField(resName).getInt(R.drawable.class);
imageView.setImageResource(resId);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
原文:http://www.cnblogs.com/rfheh/p/4124840.html
评论(0)