Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1222503
  • 博文数量: 233
  • 博客积分: 6270
  • 博客等级: 准将
  • 技术积分: 1798
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 08:32
文章分类

全部博文(233)

文章存档

2011年(31)

2010年(202)

我的朋友

分类: 嵌入式

2010-11-30 15:15:59

在开发Android软件的过程中,xml文件里经常会使用一些Android内部定义的资源和常量,我们如何获取相应的资源信息,以下做一个简要的说明。
 
使用Android资源或常量的方法,分为两种:
  • 在JAVA程序中,我们按以下方式引用资源:android.R.<资源类型>.<资源ID>,如:
    android.R.drawable.ic_menu_save
  • 在XML文件中,按以下方式引用资源: @android:<资源类型>/资源ID
    @android:drawable/ic_menu_save

 

Android定义了以下几类资源和常量可供我们使用:

参考文档:http://developer.android.com/guide/topics/resources/available-resources.html#drawables

以下所引用的路径都是"android.jar"下的相对路径

  • Animation Resources
    Define pre-determined animations.
    Tween animations are saved in res/anim/ and accessed from the R.anim class.
    Frame animations are saved in res/drawable/ and accessed from the R.drawable class.
  • Color State List Resource
    Define a color resources that changes based on the View state.
    Saved in res/color/ and accessed from the R.color class
  • Drawable Resources
    Define various graphics with bitmaps or XML.
    Saved in res/drawable/ and accessed from the R.drawable class.
  • Layout Resource
    Define the layout for your application UI.
    Saved in res/layout/ and accessed from the R.layout class.
  • Menu Resource
    Define the contents of your application menus.
    Saved in res/menu/ and accessed from the R.menu class.
  • String Resources
    Define strings, string arrays, and plurals (and include string formatting and styling).
    Saved in res/values/ and accessed from the R.string, R.array, and R.plurals classes.
  • Style Resource
    Define the look and format for UI elements.
    Saved in res/values/ and accessed from the R.style class.
  • More Resource Types
    Define values such as booleans, integers, dimensions, colors, and other arrays.
    Saved in res/values/ but each accessed from unique R sub-classes (such as R.bool, R.integer, R.dimen, etc.).

 

阅读(3706) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~