Using Resources

This section describes how to use the resources you've created. It includes the following topics:

• Using resources in code - How to call resources in your code to instantiate them.

• Referring to resources from other resources - You can reference resources from other resources. This lets you reuse common resource values inside resources.

• Supporting Alternate Resources for Alternate Configurations - You can specify different resources to load, depending on the language or display configuration of the host hardware.

At compile time, Android generates a class named R that contains resource identifiers to all the resources in your program. This class contains several subclasses, one for each type of resource supported by Android, and for which you provided a resource file. Each class contains one or more identifiers for the compiled resources, that you use in your code to load the resource. Here is a small resource file that contains string, layout (screens or parts of screens), and image resources.

Note: the R class is an auto-generated file and is not designed to be edited by hand. It will be automatically recreated as needed when the resources are updated.

package; public final class R {

public static final class string {

public static final int greeting=0x0204000e; public static final int start_button_text=0x02040001; public static final int submit_button_text=0x02 0 40 0 08; public static final int main_screen_title=0x0204000a;

public static final class layout {

public static final int start_screen=0x02070000; public static final int new_user_pane=0x02070001; public static final int select_user_list=0x02070002;

public static final class drawable {

public static final int company_logo=0x02020005; public static final int smiling_cat=0x02020006; public static final int yellow_fade_background=0x02020007; public static final int stretch_button_1=0x02020008;

0 0

Post a comment