根据资源名称获取对应资源

public static int getDrawResourceID(Context ctx, String resourceName) {
        Resources res=ctx.getResources();
        int picid = res.getIdentifier(resourceName,"mipmap",ctx.getPackageName());
        return picid;
    }


根据资源名称获取到资源id   

如果是drawable 

mipmap 换成drawable 



Drawable d = ContextCompat.getDrawable(msgView.getContext(),  android.R.drawable.ic_menu_add);

猜你喜欢

转载自blog.csdn.net/lsw8569013/article/details/78779192
今日推荐