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项目或者一个 ...
随机推荐
- HTML 权重标签的使用
<H>标签通常使用<H1><H2><H3>这3个标签是有权重加分的,<H4>用于无用途的文字标记等 非重要相关字. <H1>有别 ...
- bash切割文件
split -l 100 ./x01.txt -d -a 3 --additional-suffix=.txt 将 x01.txt文件,-l 100 按照每个100行, -d 以数字累加, -a 3 ...
- WPF 使用附加属性增加控件属性
使用附加属性增加控件属性,使得这个附加属性在使用的时候没有局限性,可以在任何的控件中使用它来增加所需要的属性,使得控件的属性使用起来非常灵活 一.自定义附加属性 using System; using ...
- 打乱数组——shuffle
在学习vue移动端音乐项目时,看到一个打乱数组函数,感觉很有意思就记录一下(意外发现:slice是个有趣的知识点) 原理:遍历数组,(let i = 0; i < _arr.length; i+ ...
- SQL Serever学习14——存储过程和触发器
存储过程 在数据库中很多查询都是大同小异,编写他们费时费力,将他们保存起来,以后执行就很方便了,把SQL语句“封装”起来. 存储过程的概念 存储过程是一组SQL语句集,经过编译存储,可以”一次编译,多 ...
- Cheatsheet: 2017 07.01 ~ 07.31
Other 8 Key Application Performance Metrics & How to Measure Them The Code Review: The Most Impo ...
- SecureCRT介绍
SecureCRT® combines rock-solid terminal(安全兼备可靠的终端) emulation with the strong encryption, broad range ...
- MyBatis 事务源码分析
先来看看在JAVA事务的相关技术,在JAVA中有两类事务,JDBC事务和JTA事务,如果是JDBC类型的事务,则是由Connection类来控制的.如果创建一个Connection对象时,没有显示调用 ...
- 原生javascript实现类似jquery on方法的行为监听
原生javascript有addEventListener和attachEvent方法来注册事件,但有时候我们需要判断某一行为甚至某一函数是否被执行了,并且能够获取前一行为的参数,这个时候就需要其他方 ...
- [HNOI2006]最短母串问题
题目大意:给定一个字符串集,求一个最短字串,使得该集合内的串都是该串的一个子串 算法:AC自动机+最短路+状压DP 注意空间限制 #include"cstdio" #include ...