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 ...
随机推荐
- 在CheckBox中,仅仅允许选择一项
作用相当于RadioButonList <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=" ...
- Android发送数据到web服务器4种方式
1./** 2. * Android中向web服务器提交数据的两种方式四种方法 3. */ 4.public class SubmitDataByHttpClientAndOrdinaryWay { ...
- Web性能优化方案
第一章 打开网站慢现状分析 在公司访问部署在IDC机房的VIP网站时会感觉很慢.是什么原因造成的?为了缩短页面的响应时间,改进我们的用户体验,我们需要知道用户的时间花在等待什么东西上. 可以跟踪一下我 ...
- Python网络编程——编写一个简单的回显客户端/服务器应用
今天将python中socket模块的基本API学习完后,照着书上的实例编写一个套接字服务器和客户端.采用python3.5版本,在注释中会标明python2和python3的不同之处. 1.代码 ( ...
- 转: seajs手册与文档之 -- 快速参考 ( ~~useful )
目录 快速参考 seajs.use seajs.config define require require.async exports module.exports 快速参考 该页面列举了 SeaJS ...
- spring 框架整合 笔记4
struts hibernate spring 先贴出框架整合需要的maven <project xmlns="http://maven.apache.org/POM/4.0.0&qu ...
- FMDB 的基本操作
在FMDB下载文件后,工程中必须导入如下文件,并使用 libsqlite3.dylib 依赖包 FMDB同时兼容ARC和非ARC工程,会自动根据工程配置来调整相关的内存管理代码. FMDB常用类: F ...
- Android事件机制全然解析
android事件是一级一级传递的,假设父控件不拦截.就传给子控件,假设父控件想要消费事件也就是拦截事件的话,须要重写这种方法 public boolean onInterceptTouchEvent ...
- eclipse导出附带源码的jar包
最近在搞Andengine游戏开发,发现andengine的jar包可以直接点击查看源码,而其他项目的jar包却看不了,因此自己研究了下如何生成可以直接查看源码的jar包. 1.eclipse中点击项 ...
- 如何优化cocos2d/x内存使用和程序大小的程序
从最初的:http://www.himigame.com/iphone-cocos2d/1043.html 译者: 在我完毕第一个游戏项目的时候.我深切地意识到"使用cocos2d来制作游戏 ...