wequick/Small

Resources.getIdentifier 找不到资源

Open

#195 创建于 2016年7月5日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)Java (1,123 fork)batch import
enhancementhelp wanted疑难杂症

仓库指标

Star
 (5,028 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

前提: lib.style 有资源 test_resource

lib.utils UIUtils.java 

    public static void testResource(Context context) {

        int c1 = context.getResources().
                getIdentifier("test_resource", "string", "net.wequick.example.small");
        int c2 = context.getResources().
                getIdentifier("test_resource", "string", "com.example.mysmall.lib.style");


        Toast.makeText(context, c1 + "   " + c2, Toast.LENGTH_SHORT).show();
        Toast.makeText(context, c1 + "   " +
                context.getResources().getResourceEntryName(c2), Toast.LENGTH_SHORT).show();
    }

现象: c1得不到资源id,c2可以。

期望: c1能得到资源id

项目中一个第三方库内部使用了这个方法,但是getIdentifier第三个参数它默认传的是context.getPackageName, 故找不到资源。

贡献者指南