wequick/Small

Resources.getIdentifier 找不到资源

Open

#195 opened on Jul 5, 2016

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Java (1,123 forks)batch import
enhancementhelp wanted疑难杂症

Repository metrics

Stars
 (5,028 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

前提: 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, 故找不到资源。

Contributor guide