Andriod(3)——Understanding Android Resources
Now, we will follow that introduction with an in-depth look at Android SDK fundamentals and cover resources , content providers, and intents. These three concepts are fundamental to understanding Android programming and should place you on a solid foundation
for the material in subsequent chapters.
1 Understanding Resources
You can change a resource without recompiling the application, and a resource in Android is a file or a value that is bound to an executable application.
Every resource has a ID, that you can change the content of the ID without changing the source code.
1 String Resource
String resource definitions is in some XML files which reside in the subdirectory as follows:
res/values
When the file is created or updated, the Eclipse ADT plug-in will automatically create or update a Java class in your applications's root package called R.java with unique IDs for the two string resources specified.
R.java just like this:
The two static final ints defined with variable names hello and app_name are the resource IDs that represent the corresponding string resources. You could use these resource iDs anywhere in the source code through the following code structure:
R.string.hello
2 Layout Resources
In Android, the view of a screen is often loaded from an XML file as resource.These XML files are called layout resources. A layout resource is a key resource used in Android UI programming.
setContentView(R.layout.main);
This line points out htat there is a static class called R.layout, and within that class, there is a constant called main(an integer), pointing to a View defined by an XML layout resource file. This statement expects the programmer to create the file /res/layout/main.xml
and place the necessary layout definition in that file.
A LinearLayout lays out its children vertically or horizontally.
You will need to define a separate layout file for each screen (or activity). More accurately, each layout needs a dedicated file.
The views defined in layout files are accessible in java code through their resource IDs generated in R.java.
TextView tv = (TextView)this.findViewById(R.id.text1);
tv.setText("Try this text instead");
The constant R.id.text1 corresponds to the ID defined for the TextView. The id for the TextView in the layout file is as follows:
<TextView android:id="@+id/text1"
..
</TextView>
The constant called text1 will be used to uniquely identify this view among other views hosted by that activity. The plus sign (+) in @+id/text1 means that the ID text1 will be created if it doesn't exist already.
3 Resource Reference Syntax
The syntax you use to allocate an id to a resource in the XML file is called resource-reference syntax.
The id attribute syntax in the previous example @+id/text1 has the following formal structure:
@[package:]type/name
Andriod(3)——Understanding Android Resources的更多相关文章
- understanding android build layer · Dylan
build / android 先看看Android官方的解释 Understand Build Layers The build hierarchy includes the abstraction ...
- cocos2dx android resources.ap_ does not exist
当我们在eclipse中打开cocos2dx自动创建的工程时,经常会出现错误: cocos2dx android resources.ap_ does not exist 这是因为android工程的 ...
- android resources使用总结
http://developer.android.com/guide/topics/resources/more-resources.html http://developer.android.com ...
- Illegal resource reference: @*android resources are private and not always present
0:前言 在android开发中,当使用别人的代码的时候,在style.xml中有此种错误 1:解决方案 删除*星号
- Andriod的国际化-android学习之旅(五十八)
android资源国际化
- Understanding Android Security(安卓安全的理解)
论文作者: Enck, William Ongtang, MacHigar McDaniel, Patrick 下一代的开放操作系统不会在个人主机和大型主机上出现,而是在只能手机上.新环境的开放性将会 ...
- android Resources 类的使用
使用 R.<resource_type>.<resource_name> 获取的是资源的一个 id (int 类型), 但有时候我们需要获取资源本身,这时候我们可以通过 Res ...
- Android Resources
Ref:Android开发最佳实践 Ref:Android高手速成--第一部分 个性化控件(View) Ref:Android高手速成--第二部分 工具库 Ref:Android高手速成--第三部分 ...
- Andriod Unity 调用android函数
//首先这是一个前沿 //我看了多的资料,还看了近半个小时的 android activity 的讲解 终于打出了apk //接下来开始 //一步一步的跟着我走 1.创建一个android项目或者一个 ...
随机推荐
- 利用keepalived构建高可用MySQL-HA
关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储,但是它们各有优缺点.heartbeat.drbd配置较为复杂,需要自己写脚本才能实现MySQL自动切换,对 ...
- Linux原始套接字实现分析---转
http://blog.chinaunix.net/uid-27074062-id-3388166.html 本文从IPV4协议栈原始套接字的分类入手,详细介绍了链路层和网络层原始套接字的特点及其内核 ...
- TP2.1 加载扩展配置文件参数
维护老项目真的恶心!!!!!!!!! TP3.2好像有这样一个配置参数,可以设置有那些扩展配置文件,系统会自动加载. 方法一: 'LOAD_EXT_CONFIG' => 'user,db',// ...
- WCF WCF的宿主
一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类契约的定 ...
- 十六、Condition等待通知
一.简介 我们可以使用syncronized和wait,notify实现等待通知.而syncronized的高级实现Lock,也可以实现等待通知,需要构造Condition的实例对象. JDK文档:h ...
- 如何迎接新的 .NET 时代
看完.NET 基金会. Roslyn 编译器 ,应该已经能慢慢了解,现在所谓的“.NET 开源”.“.NET Open Source”并不是完全把现有的 .NET Framework 整个打开(虽然这 ...
- 军事机密(Secret.pas)
军事机密(Secret.pas) [问题描述] 军方截获的信息由n(n<=30000)个数字组成,因为是敌国的高端秘密,所以一时不能破获.最原始的想法就是对这n个数进行小到大排序, ...
- bootstrap学习笔记细化(表格)
主要属性: 全屏宽度带水平线的表格 .table 带边框的表格 .table-bordered 条纹状表格 .table-striped 悬停变色表格 .table-hover 紧凑风格表格 .tab ...
- Css选择器(上) 让样式无孔不入
css选择器 一个可以选择样式的工具, 这里适用于无论是内部代码还是外部引用 abc.css 这类型的文件. 基本选择器*{ } 就是一个简单的*, 代表应用于全部. 不适合于个性 ...
- gulp & webpack整合
为什么需要前端工程化? 前端工程化的意义在于让前端这个行业由野蛮时代进化为正规军时代,近年来很多相关的工具和概念诞生.好奇心日报在进行前端工程化的过程中,主要的挑战在于解决如下问题:✦ 如何管理多个项 ...