public static int getResourceId(String name){
int drawableId = -1 ;
try {
Class<drawable> res = R.drawable.class;
Field field = res.getField(name);
drawableId = field.getInt(null);
} catch (Exception e) {
e.printStackTrace();
}
return drawableId;
}
Method 2:
Using Android Resources API.
public int getIdentifier (String name, String defType, String defPackage)
沒有留言:
張貼留言