Android 如何引用com.android.internal.R目录下的资源
Android 如何引用com.android.internal.R目录下的资源
项目需求
有一个资源跟系统上的一个资源相同,想要引用它:frameworks/base/core/res/res/drawable/ic_text_dot.xml
文件名称:ic_text_dot.xml
文件的具体内容:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:inset="10dp">
<shape android:shape="oval">
<solid android:color="?android:attr/textColorSecondary" />
<size android:width="4dp" android:height="4dp" />
</shape>
</inset>
该资源在代码中的引用是:com.android.internal.R.drawable.ic_text_dot
遇到的问题
但是不知道为什么,我在项目中用Java代码调用这个资源的时候,一直提示失败,无法找到目标:
ImageView imageView = (ImageView) findViewById(R.id.img);
imageView.setImageDrawable(getDrawable(com.android.internal.R.drawable.ic_text_dot));
//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.
解决的办法是:
ImageView imageView = (ImageView) findViewById(R.id.img);
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目录下的资源的更多相关文章
- android访问asset目录下的资源
android提供了AssetManager来访问asset目录下的资源, 在activity中通过getAssets()获取AssetManager 常用的api如下: 1.列举路径下的资源Stri ...
- 安卓获取Assets目录下的资源
获取Assets目录下的资源 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 ! ...
- Android读取assets目录下的资源
1.获取资源的输入流 资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“s ...
- Unity3d 枚举某个目录下所有资源
using UnityEngine; using System.Collections; using UnityEditor; using System.Collections.Generic; us ...
- Asp.Net配置不允许通过url方式访问目录下的资源
Asp.Net网站发布后,有部分文件为了安全性,是不能直接通过url访问获取 通常有2种做法: 1.将文件目录建立在 App_code 或者App_Data 等默认的隐藏目录下 2.将文件的目录添加到 ...
- Java获取/resources目录下的资源文件方法
Web项目开发中,经常会有一些静态资源,被放置在resources目录下,随项目打包在一起,代码中要使用的时候,通过文件读取的方式,加载并使用: 今天总结整理了九种方式获取resources目录下文件 ...
- Android工程:引用另一个Android工程的方法详解
本篇文章是对在Android中引用另一个Android工程的方法进行了详细的分析介绍.需要的朋友参考下 现在已经有了一个Android工程A.我们想扩展A的功能,但是不想在A的基础上做开发,于是新 ...
- Android开发之assets目录下资源使用总结
预前知识: Android资源文件分类: Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.Java里面自动生成该资源文件的ID,所以访问 ...
- Android开发自学笔记(Android Studio1.3.1)—3.Android应用结构解析
一.R文件是什么? 如上图所示,我们可以通过findViewById方法通过传入R.id.show找到我们的TextView元素,findViewById方法也很好理解,从View中通过Id ...
随机推荐
- Webform中Repeater控件--绑定嵌入C#代码四种方式
网页里面嵌入C#代码用的是<% %>,嵌入php代码<?php ?> 绑定数据的四种方式: 1.直接绑定 <%#Eval("Code") %> ...
- 学习validate
jQuery Validate (转自http://www.w3cschool.cc/jquery/jquery-plugin-validate.html?utm_source=tuicool) jQ ...
- springdata+redis配置详解
springdata设计初衷是位简化数据类型和数据的持久化存储,它并不局限是关系型数据库还是nosql数据库,都提供了简化的数据库连接,让数据获取变得更加的简单.所有这些的实现有统一的api提供. 本 ...
- mysql性能调优与架构设计(一)商业需求与系统架构对性能的影响
这里我们就拿一个看上去很简单的功能来分析一下. 需求:一个论坛帖子总量的统计附加要求:实时更新 在很多人看来,这个功能非常容易实现,不就是执行一条SELECT COUNT(*)的Query 就可以得到 ...
- python安装zlib一直无效
一直按网上的方法: 1.先安装 apt-get install zlib1g-dev 2.重新安装python(3.3):即是./configure 再make再make install 始终没有解决 ...
- Python之路Day14
主要内容:jQuery进阶.CSS伪类和伪元素.jQuery插件 tab菜单样式 checkbox全选.反选 位置:scrollTop和offset 事件:两种绑定事件的方式和委托delegate a ...
- 再次复习数据结构:c语言链表的简单操作
最近呢,又要面临多次的数据结构与算法方面的试题了,而我呢,大概也重新温习c语言的基本要点快一个月了,主要是针对指针这货的角度在研究c语言,感觉又学到了不少. 现在c指针感觉知道点了,也就匆忙开展数据结 ...
- MouseOver/MouseOut vs MouseEnter/MouseLeave
参考 http://www.oschina.net/question/234345_45280 这是jQuery提供的函数 要注意MouseOut 和 MouseLeave的区别 比如对元素A绑定Mo ...
- mysql-5.6.17-winx64 免安装 配置
[client] default_character_set=utf8 port=3306 [mysql] # 设置mysql客户端默认字符集 default_character_set=utf8 [ ...
- php重定向页面的三种方式
PHP页面跳转一.header()函数 header()函数是PHP中进行页面跳转的一种十分简单的方法.header()函数的主要功能是将HTTP协议标头(header)输出到浏览器. header( ...