How do I get the resource id of an image if I know its name? [duplicate] Ask Question

How do I get the resource id of an image if I know its name? [duplicate] Ask Question

How do I get the resource id of an image if I know its name (in Android)?

ベストアンサー1

With something like this:

String mDrawableName = "myappicon";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());

おすすめ記事