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

来源:互联网 发布:iso软件标准 编辑:程序博客网 时间:2024/05/16 03:01
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);

原创粉丝点击