使用Android自带的资源

Android自带的资源文件有 :https://developer.android.google.cn/reference/android/R.html

代码中使用如下:

1.查看源代码的资源文件

2代码调用如下:

//获取系统String资源
        int lebId = Resources.getSystem()
                .getIdentifier("permlab_accessNetworkState",
                        "string", "android");
        String lab = getString(lebId);
        Toast.makeText(MainActivity.this, lab, Toast.LENGTH_SHORT).show();
        //获取系统drawable资源
        ImageView imageView = (ImageView) findViewById(R.id.iv);
        int okId = Resources.getSystem()
                .getIdentifier("sym_keyboard_feedback_ok",
                        "drawable", "android");
        imageView.setImageResource(okId);

getIdentifier方法参数

name :资源名称  
defType:资源类型  
defPackage:资源所在包
原文地址:https://www.cnblogs.com/loaderman/p/6927191.html