//得到该图片的id(name 是该图片的名字,"drawable" 是该图片存放的目录,getPackageName()是应用程序的包)

int resID = getResources().getIdentifier(name, "drawable", getPackageName());
((ImageView) tabView.findViewById(R.id.on)).setImageDrawable(getResources().getDrawable(resID));

 

PS:千万不要把图片目录名或图片名写错了,今天我就把“drawable”,写成了“drawble”,结果就报了资源找不到的错误,大家引以为戒。

相关文章:

  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案