How to get a resource id with a known resource name?

前端 未结 10 1439
挽巷
挽巷 2020-11-21 23:31

I want to access a resource like a String or a Drawable by its name and not its int id.

Which method would I use for this?

10条回答
  •  终归单人心
    2020-11-22 00:19

    int resourceID = 
        this.getResources().getIdentifier("resource name", "resource type as mentioned in R.java",this.getPackageName());
    

提交回复
热议问题