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的更多相关文章

  1. understanding android build layer · Dylan

    build / android 先看看Android官方的解释 Understand Build Layers The build hierarchy includes the abstraction ...

  2. cocos2dx android resources.ap_ does not exist

    当我们在eclipse中打开cocos2dx自动创建的工程时,经常会出现错误: cocos2dx android resources.ap_ does not exist 这是因为android工程的 ...

  3. android resources使用总结

    http://developer.android.com/guide/topics/resources/more-resources.html http://developer.android.com ...

  4. Illegal resource reference: @*android resources are private and not always present

    0:前言 在android开发中,当使用别人的代码的时候,在style.xml中有此种错误 1:解决方案 删除*星号

  5. Andriod的国际化-android学习之旅(五十八)

    android资源国际化

  6. Understanding Android Security(安卓安全的理解)

    论文作者: Enck, William Ongtang, MacHigar McDaniel, Patrick 下一代的开放操作系统不会在个人主机和大型主机上出现,而是在只能手机上.新环境的开放性将会 ...

  7. android Resources 类的使用

    使用 R.<resource_type>.<resource_name> 获取的是资源的一个 id (int 类型), 但有时候我们需要获取资源本身,这时候我们可以通过 Res ...

  8. Android Resources

    Ref:Android开发最佳实践 Ref:Android高手速成--第一部分 个性化控件(View) Ref:Android高手速成--第二部分 工具库 Ref:Android高手速成--第三部分 ...

  9. Andriod Unity 调用android函数

    //首先这是一个前沿 //我看了多的资料,还看了近半个小时的 android activity 的讲解 终于打出了apk //接下来开始 //一步一步的跟着我走 1.创建一个android项目或者一个 ...

随机推荐

  1. Linux Ubuntu系统下Java开发环境搭建

    操作系统:Linux x64 / Ubuntu 14.04 Java JDK版本:jdk-8u65-linux-x64.tar.gz 声明:转载请注明出处及本文链接 1. 前往ORACLE官网下载最新 ...

  2. redis数据类型(五)set类型

    一. set类型 set是无序集合,最大可以包含(2 的 32 次方-1)个元素. set 的是通过 hash table 实现的,所以添加,删除,查找的复杂度都是 O(1). hash table ...

  3. MVC5 知识点记录

    http://blog.csdn.net/qinkeliangqin/article/details/27084639#t27 一.概述 MVC简介: •       模型(Model) “数据模型” ...

  4. Python(3):文件读写与异常

    访问路径: 文件读写必然涉及到文件会放在某个路径下.在python里,可以通过引入os包来实现切换当前访问的路径: # 假设我在 /home/zyq/KiDe/Python/test 文件夹中有一个文 ...

  5. 深度为君剖析CTO、技术总监、首席架构师的区别

      CTO.技术总监.首席架构师的区别 经常有创业公司老板来拜访我,常常会拜托给我一句话:帮我找一个CTO. 我解释的多了,所以想把这个写下来,看看你到底需要的应该是啥. 一.高级程序员 如果你是一个 ...

  6. ayer.prompt 怎样让输入值为空也可以向下执行

    http://fly.layui.com/jie/4227/ layer.prompt({title: '输入任何口令,并确认',formType: 1, //prompt风格,支持0-2value: ...

  7. 怎样在 Azure 应用服务中生成和部署 Java API 应用

    先决条件 Java 开发人员工具包 8(或更高版本) 已在开发计算机上安装 Maven 已在开发计算机上安装 Git Azure 订阅付费版或试用版 HTTP 测试应用程序,如 Postman 使用 ...

  8. 述一个程序员的技能:系统安装(win7版)idea配置

    idea配置:http://www.phperz.com/article/15/0923/159043.html 作为一名计算机专业出身的程序员,组装电脑和安装系统是基本技能.打造一个安全稳定高效的开 ...

  9. oracle lpad rpad函数

    学习并记录 1.情况一 ) from dual; 运行结果如下: email长度5,默认添加3个空格在左边 2.情况二 ) from dual; 运行结果如下: email长度5,截取2两个字符 3. ...

  10. Core.Java.Volume.I.Fundamentals.10th.Edition 14.5.8 Volatile域 中文版 章节勘误

    今天重扫了corejava 14 并发的一章,在谈到volatile域代替synchronized 应用于并发更新时,看到如下内容,并发更新可用内部锁的方式但会带来阻塞问题,可用volatile域替代 ...