Android动态获取图片资源

Android动态获取图片资源

动态加载icon1,icon2,icon3,怎么以变量的形式加载图片资源呢?
使用 .getResources().getIdentifier(“图片资源名”,“drawable”,“包名”)

 String iconName="icon"+a; //图片资源名称 a为一个变量
 int goodsIcon=MyApplication.getContext().getResources().getIdentifier(iconName, "drawable", "com.domain.mainView");
  //第一个参数为资源名称,第二个为资源所在文件夹,第三个为包名
  //MyApplication.getContext()为全局context,我是在adapter中使用的context

猜你喜欢

转载自blog.csdn.net/Qingshan_z/article/details/128137317
今日推荐