Android 如何引用com.android.internal.R目录下的资源

项目需求

有一个资源跟系统上的一个资源相同,想要引用它:frameworks/base/core/res/res/drawable/ic_text_dot.xml

文件名称:ic_text_dot.xml

文件的具体内容:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Copyright (C) 2014 The Android Open Source Project
  3.  
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7.  
  8. http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <inset xmlns:android="http://schemas.android.com/apk/res/android"
  17. android:inset="10dp">
  18. <shape android:shape="oval">
  19. <solid android:color="?android:attr/textColorSecondary" />
  20. <size android:width="4dp" android:height="4dp" />
  21. </shape>
  22. </inset>

该资源在代码中的引用是:com.android.internal.R.drawable.ic_text_dot

遇到的问题

但是不知道为什么,我在项目中用Java代码调用这个资源的时候,一直提示失败,无法找到目标:

  1. ImageView imageView = (ImageView) findViewById(R.id.img);
  2. imageView.setImageDrawable(getDrawable(com.android.internal.R.drawable.ic_text_dot));
  3. //com.android.internal.R cannot be resolved to a variable

出现问题的原因

You cannot access id's of com.android.internal.R at compile time, but you can access the defined internal resources at runtime and get the resource by name.

解决的办法是:

  1. ImageView imageView = (ImageView) findViewById(R.id.img);
  2. imageView.setImageResource(Resources.getSystem().getIdentifier("ic_text_dot", "drawable", "android"));

参考:http://stackoverflow.com/questions/3486819/how-to-resolve-the-error-com-android-internal-r-cannot-be-resolved-when-i-usin

  

  

Android 如何引用com.android.internal.R目录下的资源的更多相关文章

  1. android访问asset目录下的资源

    android提供了AssetManager来访问asset目录下的资源, 在activity中通过getAssets()获取AssetManager 常用的api如下: 1.列举路径下的资源Stri ...

  2. 安卓获取Assets目录下的资源

    获取Assets目录下的资源 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 ! ...

  3. Android读取assets目录下的资源

    1.获取资源的输入流 资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“s ...

  4. Unity3d 枚举某个目录下所有资源

    using UnityEngine; using System.Collections; using UnityEditor; using System.Collections.Generic; us ...

  5. Asp.Net配置不允许通过url方式访问目录下的资源

    Asp.Net网站发布后,有部分文件为了安全性,是不能直接通过url访问获取 通常有2种做法: 1.将文件目录建立在 App_code 或者App_Data 等默认的隐藏目录下 2.将文件的目录添加到 ...

  6. Java获取/resources目录下的资源文件方法

    Web项目开发中,经常会有一些静态资源,被放置在resources目录下,随项目打包在一起,代码中要使用的时候,通过文件读取的方式,加载并使用: 今天总结整理了九种方式获取resources目录下文件 ...

  7. Android工程:引用另一个Android工程的方法详解

    本篇文章是对在Android中引用另一个Android工程的方法进行了详细的分析介绍.需要的朋友参考下   现在已经有了一个Android工程A.我们想扩展A的功能,但是不想在A的基础上做开发,于是新 ...

  8. Android开发之assets目录下资源使用总结

    预前知识: Android资源文件分类: Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.Java里面自动生成该资源文件的ID,所以访问 ...

  9. Android开发自学笔记(Android Studio1.3.1)—3.Android应用结构解析

    一.R文件是什么?      如上图所示,我们可以通过findViewById方法通过传入R.id.show找到我们的TextView元素,findViewById方法也很好理解,从View中通过Id ...

随机推荐

  1. 制作自己的私有库(cocopods)

    1.首先你需要创建一个私有的仓库,用于存放自己的podspec相关文件,至于git服务器你可以用http://git.oschina.net/,或者自己搭建的都行.我在git服务器上创建了一个名字叫T ...

  2. iOS推送证书p12转成pem

    首先你需要导出p12格式的证书,具体操作请参考如下: 其次你就可以通过在控制台输入如下命令即可转换: openssl pkcs12 -in 你导出的p12证书 -out 你要转换的pem证书 -nod ...

  3. 学习validate

    jQuery Validate (转自http://www.w3cschool.cc/jquery/jquery-plugin-validate.html?utm_source=tuicool) jQ ...

  4. 《算法导论》读书笔记之排序算法—Merge Sort 归并排序算法

    自从打ACM以来也算是用归并排序了好久,现在就写一篇博客来介绍一下这个算法吧 :) 图片来自维基百科,显示了完整的归并排序过程.例如数组{38, 27, 43, 3, 9, 82, 10}. 在算法导 ...

  5. Python IDLE快捷键

    编辑状态时:Ctrl + [ .Ctrl + ] 缩进代码Alt+3 Alt+4 注释.取消注释代码行Alt+5 Alt+6 切换缩进方式 空格<=>TabAlt+/ 单词完成,只要文中出 ...

  6. Week15(12月16日):授课综述1

    Part I:提问 =========================== 1.(   )类提供了一个对Entity Framework的抽象,能够进行数据持久化并接受数据. A.Layout    ...

  7. sorl6.0+jetty+mysql

    sorl6.0+jetty+mysql搭建solr服务 1.下载solr 官网:http://lucene.apache.org/solr/ v2.目录结构如下 v3.启动solr(默认使用jetty ...

  8. poco vs Boost

    Wooce Yang收集整理 POCO的优点: 1) 比boost更好的线程库,特别是一个活动的方法的实现,并且还可设置线程的优先级. 2) 比 boost:asio更全面的网络库.但是boost:a ...

  9. UI 响应者链

    响应者链  概念: 每一个应用有一个响应者链,我们的视图结构是一个N叉树(一个视图可以有多个子视图,一个子视图同一时刻只有一个父视图),而每一个继承UIResponder的对象都可以在这个N叉树中扮演 ...

  10. 1354 - IP Checking(水题)

    1354 - IP Checking   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...