Use the Getidentifier () method to easily obtain the specified resource ID under each application package.
There are two main ways of doing this:
(1) mode one
Resources resources = Context.getresources ();
int indentify = resources. Getidentifier (Org.loveandroid.androidtest:drawable/icon ", null,null);
if (indentify>0) {
icon = resources.getdrawable (indentify);
}
The first parameter format is: Package name +: + Resource folder name +/+ resource name; Is this format and the other can be null
(2) mode two
Resources resources = Context.getresources ();
Intindentify= getresources (). Getidentifier ("icon", "drawable", "Org.anddev.android.testproject");
The first parameter is the ID name, the second is the resource attribute is the ID or the drawable, and the third is the package name.
Returns the resource ID if found, and returns 0 if it is not found.
Reference URL: http://blog.csdn.net/fengye810130/article/details/9314347
Getidentifier () Get Resources