How to replace R.drawable.“someString”

后端 未结 6 985
长发绾君心
长发绾君心 2021-02-02 10:00

I have some Images in my project. The name of the image is stored in a String and I would like to setImageResource(R.drawable.\".....\"); with the string of the image name but t

6条回答
  •  梦毁少年i
    2021-02-02 10:12

    I got it working by moving the image from 'drawable' to 'raw' folder and access the string value as below. If you do not have 'raw' folder under 'res' directory, right click on res->new->Android resource directory and under dropdown of resourcetype, select 'raw'.

        String avatar = ("android.resource://" + "yourPackageName/" + String.valueOf(R.raw.robot_blue));
    

提交回复
热议问题