android 在res资源下的图片,根据图片名称加载图片

    xiaoxiao2021-03-25  106

    我们可能有需求遇到,只根据图片名称加载res里的图片资源。

    代码示例:

    res\drawable\p1.jpg

    int resId = mContext.getResources().getIdentifier("p1", "drawable" , mContext.getPackageName()); Uri uri = Uri.parse("res:///"+resId);

    再比如,我要根据id名获取array-string数组

    int resId = mContext.getResources().getIdentifier("idname", "array" , mContext.getPackageName());

    我们发现 R.array.xx

    R.drawable.xx

    getIdentifier(, defType , );

    defType = array|drawable|…

    转载请注明原文地址: https://ju.6miu.com/read-16953.html

    最新回复(0)