2013年8月14日 星期三

Resource


A resource is a piece of your application that is not code – things like image files, audio files, and XML files.


To access a resource in code, you use its resource ID

resource ID is int

查詢Resource ID

gen/R.java





android:id="@+id/example"

The at symbol (@) signifies that you’re referring to a resource rather than providing a literal value. The plus (+) indicates that you are creating a new resource reference; without it, you’re referring to an existing resource reference. Then comes id, defining what type of resource it is. Finally, you have the name of the resource

directory res is for resource

Resource Qualifiers
By using resource “qualifiers,” you can let Android take care of this for you.
A qualifier is a portion of a directory’s name that marks its contents as being used for a specific situation
ex:

ldpi
mdpi
hdpi



resource folder name

animator: Property animations defined in XML.
anim: View animations defined in XML.
color: State lists of colors defined in XML. State lists are covered later in this chapter.
drawable: Drawable assets that can be defined in XML or image files (PNG, GIF, or JPG).
layout: Layouts defined in XML.
menu: Menus such as the action bar menu defined in XML.
raw: Any raw files such as audio files and custom bytecode.
values: Various simple values defined in XML, such as strings, floats, and integer colors.
xml: Any XML files you wish to read at runtime.


other resources:
Strings

Arrays
Colors
Dimensions
Animations




沒有留言:

張貼留言