方法1
public static int getResourceId(Context context, String resourceName, String resourceType) {
return context.getResources().getIdentifier(resourceName, resourceType,
context.getPackageName());
}
//Resource ID type
// public static final String ID_TYPE_STRING = "string";
// public static final String ID_TYPE_MIPMAP = "mipmap";
// public static final String ID_TYPE_DRAWABLE = "drawable";
方法2
而是存放在src某个package中(如:com.drawable.resource),这种情况下的调用方法为:
String path = “com/drawable/resource/test.png.png”;
InputStream is = getClassLoader().getResourceAsStream(path);
Drawable.createFromStream(is, “src”);
方法3
放在asset文件夹里面
InputStream is = getResources().getAssets().open(“test.png”);
Drawable d = Drawable.createFromStream(is, null);