Sie sind auf Seite 1von 18

Lecture 3

MANAGING RESOURCES

Resources in Android
Externalizing resources from application code images and strings

alternative resources that support specific device configurations


different languages or screen sizes For any type of resource, you can specify default and multiple alternative resources for your application res/ directory

Providing Resources
Once you externalize your application resources, you can access them by ID that are generated in your project's R class

Resource Directories

Resource Types
Animation ColorStateList Resource

Drawable Resources
Menu Resource String Resources Style Resource Color Resource

More resource types


Bool XML resource that carries a boolean value. Color

XML resource that carries a color value (a hexadecimal color).


Dimension XML resource that carries a dimension value (with a unit of measure). Integer resource that carries an integer value. Integer Array XML resource that provides an array of integers. Typed Array XML resource that provides a TypedArray (which you can use for an array of drawables).

Examples: Drawable Resources


Path: res/drawable/myimage Bitmap

formats: .png , .jpg .gif (discouraged).

Read more about Drawables


Drawable Resources http://developer.android.com/guide/topics/resources/drawable-resource.html

Color Resources Example


Color representation : values/mycolors.xml #RGB or #ARGB or #RRGGBB or #AARRGGBB

Access it in xml layout through

String Resources Example


Path : values/strings.xml

Access it in xml layout through

Style Resources Example


Path : values/styles.xml

Access it in xml layout through

String Array & Typed Array Example

Color State List Resources


Path: res/color/btn_color.xml

Access it in xml layout through

Same for images


Path :res /drawable/btn_images.xml

Access it in xml layout through

Accessing Resources
Accessing Resources in Code

Get Resources contents

Accessing Resources In XML


@[<package_name>:]<resource_type>/<resource_name> E.g. @string/hello

Read more about resources


http://developer.android.com/guide/topics/resources/index.html

Das könnte Ihnen auch gefallen