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

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

 

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

相关文章:

  • 2021-09-05
  • 2021-09-01
  • 2021-11-14
  • 2021-05-21
  • 2021-05-23
  • 2021-09-13
  • 2021-09-13
  • 2021-05-09
猜你喜欢
  • 2021-08-26
  • 2021-09-13
  • 2021-04-13
  • 2021-09-13
  • 2021-11-17
  • 2021-11-02
  • 2021-07-25
  • 2021-09-13
相关资源
相似解决方案