Android根据图片名称加载Drawable里面的图片并且显示

public static int getimages(String name){
    Class drawable = R.drawable.class;
    Field field = null;
    try {
        field =drawable.getField(name);
        int images = field.getInt(field.getName());
        return images;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

你可能感兴趣的:(Android根据图片名称加载Drawable里面的图片并且显示)