If you need a resource in Android development, use the r.drawable.** file directly. However, if at first you do not know which resource file to load, you must obtain the ID value dynamically in the program and load it. The loading process is loaded using the file name, as follows:
public static String Resource_path = "android.resource://PackageName/";
Suppose there is a resource picture named Content_icon
Public Uri Geticonuri (String drawablename) {
if (Drawablename = = null) {
return uri.empty;
}
Return Uri.parse (Drawablename);
}
Flag.png, for example, can be used:
int idflag = Getresources (). Getidentifier (Getpackagename () + ":d Rawable/flag", NULL, NULL);
Or
int idflag = Getresources (). Getidentifier ("Flag", "drawable", Getpackagename ());
int idflag = Getresources (). Getidentifier (Getpackagename () + ":d Rawable/flag", NULL, NULL);
Or
int idflag = Getresources (). Getidentifier ("Flag", "drawable", Getpackagename ());
Here, how to get Flag1.png ~ Flag10.png drawable Objects, the code is as follows:
var drawable[] dw = new DRAWABLE[10];
for (int i = 1; i <=; i++) {
int id = getresources (). Getidentifier ("flag" + I, "drawable", Getpackagename ());
Dw[i-1] = Getresources (). getdrawable (ID);
}
Android code loads a resource file with a known file name