resources-i18n.jd revision d24b8183b93e781080b2c16c487e60d51c12da31
1page.title=Resources and Internationalization
2parent.title=Resources and Assets
3parent.link=index.html
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8
9  <h2>Key classes</h2>
10  <ol>
11    <li>{@link android.content.res.Resources}</li>
12  </ol>
13
14  <h2>In this document</h2>
15  <ol>
16    <li><a href="#intro">Introduction</a></li>
17    <li><a href="#CreatingResources">Creating Resources</a></li>
18    <li><a href="#UsingResources">Using Resources</a>
19      <ol>
20        <li><a href="#ResourcesInCode">Using Resources in Code</a></li>
21        <li><a href="#ReferencesToResources">References to Resources</a></li>
22        <li><a href="#ReferencesToThemeAttributes">References to Theme Attributes</a></li>
23        <li><a href="#UsingSystemResources">Using System Resources</a></li>
24      </ol>
25    </li>
26    <li><a href="#AlternateResources">Alternate Resources</a></li>
27    <li><a href="#ResourcesTerminology">Terminology</a></li>
28    <li><a href="#i18n">Internationalization (I18N)</a></li>
29  </ol>
30</div>
31</div>
32
33<p>Resources are external files (that is, non-code files) that are used by
34your code and compiled into your application at build time. Android
35supports a number of different kinds of resource files, including XML,
36PNG, and JPEG files. The XML files have very different formats depending
37on what they describe. This document describes what kinds of files are
38supported, and the syntax or format of each.</p>
39<p>Resources are externalized from source code, and XML files are compiled into
40a binary, fast loading format for efficiency reasons. Strings, likewise are compressed
41into a more efficient storage form. It is for these reasons that we have these
42different resource types in the Android platform.</p>
43
44<p>This is a fairly technically dense document, and together with the
45<a href="available-resources.html">Available Resources</a>
46document, they cover a lot of information about resources. It is not necessary
47to know this document by heart to use Android, but rather to know that the
48information is here when you need it.</p>
49
50<a name="intro"></a>
51<h2>Introduction</h2>
52
53<p>This topic includes a terminology list associated with resources, and a series
54    of examples of using resources in code. For a complete guide to the supported 
55    Android resource types, see 
56    <a href="available-resources.html">Available Resources</a>.
57    </p>
58<p>The Android resource system keeps track of all non-code
59    assets associated with an application.  You use the
60    {@link android.content.res.Resources Resources} class to access your
61    application's resources; the Resources instance associated with your
62    application can generally be found through
63    {@link android.content.Context#getResources Context.getResources()}.</p>
64<p>An application's resources are compiled into the application
65binary at build time for you by the build system.  To use a resource,
66you must install it correctly in the source tree and build your
67application.  As part of the build process, symbols for each
68of the resources are generated that you can use in your source
69code -- this allows the compiler to verify that your application code matches
70up with the resources you defined.</p>
71
72<p>The rest of this section is organized as a tutorial on how to
73use resources in an application.</p>
74
75<a name="CreatingResources" id="CreatingResources"></a>
76<h2>Creating Resources</h2>
77
78<p>Android supports string, bitmap, and many other types of resource. The syntax and format
79of each, and where they're stored, depends upon the type of object. In
80general, though, you create resources from three types of files: XML files
81(everything but bitmaps and raw), bitmap files(for images) and Raw files (anything
82else, for example sound files, etc.). In fact, there are two different types of
83XML file as well, those that get compiled as-is into the package, and those that
84are used to generate resources by aapt. Here is a list of each
85resource type, the format of the file, a description of the file, and details
86of any XML files. </p>
87
88<p>You will create and store your resource files under the appropriate
89subdirectory under the <code>res/</code> directory in your project. Android
90has a resource compiler (aapt) that compiles resources according to which
91subfolder they are in, and the format of the file. Here is a list of the file
92types for each resource. See the 
93<a href="available-resources.html">Available Resources</a> for
94descriptions of each type of object, the syntax, and the format or syntax of
95the containing file.</p>
96
97<table width="100%" border="1">
98    <tr>
99        <th scope="col">Directory</th>
100        <th scope="col">Resource Types </th>
101    </tr>
102    <tr>
103        <td><code>res/anim/</code></td>
104        <td>XML files that are compiled into 
105        <a href="available-resources.html#animationdrawable">frame by
106        frame animation</a> or 
107        <a href="available-resources.html#tweenedanimation">tweened
108        animation</a> objects </td>
109    </tr>
110    <tr>
111        <td><code>res/drawable/</code></td>
112        <td><p>.png, .9.png, .jpg files that are compiled into the following
113                Drawable resource subtypes:</p>
114            <p>To get a resource of this type, use <code>Resource.getDrawable(<em>id</em>)</code>
115            <ul>
116                <li><a href="available-resources.html#imagefileresources">bitmap files</a></li>
117                <li><a href="available-resources.html#ninepatch">9-patches (resizable bitmaps)</a></li>
118            </ul></td>
119    </tr>
120    <tr>
121        <td><code>res/layout/</code></td>
122        <td>XML files that are compiled into screen layouts (or part of a screen).
123            See <a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a></td>
124    </tr>
125    <tr>
126        <td><code>res/values/</code></td>
127        <td><p>XML files that can be compiled into many kinds of resource.</p>
128            <p class="note"><strong>Note:</strong> unlike the other res/ folders, this one
129            can hold any number of files that hold descriptions of resources to create
130            rather than the resources themselves. The XML element types control
131            where these resources are placed under the R class.</p>
132            <p>While the files can be named anything, these are
133                the typical files in this folder (the convention is to name
134                the file after the type of elements defined within):</p>
135            <ul>
136                <li><strong>arrays.xml</strong> to define arrays </li>  
137                <!-- TODO: add section on arrays -->
138                <li><strong>colors.xml</strong> to define <a href="available-resources.html#colordrawableresources">color
139                        drawables</a> and <a  href="#colorvals">color string values</a>.
140                        Use <code>Resources.getDrawable()</code> and
141                        <code>Resources.getColor(), respectively,</code>
142                to get these resources.</li>
143                <li><strong>dimens.xml</strong> to define <a href="available-resources.html#dimension">dimension value</a>. Use <code>Resources.getDimension()</code> to get
144                these resources.</li>
145                <li><strong>strings.xml</strong> to define <a href="available-resources.html#stringresources">string</a> values (use either         
146                <code>Resources.getString</code> or preferably <code>Resources.getText()</code>
147                to get
148                these resources. <code>getText()</code> will retain any rich text styling
149                which is usually desirable for UI strings.</li>
150                <li><strong>styles.xml</strong> to define <a href="available-resources.html#stylesandthemes">style</a> objects.</li>
151            </ul></td>
152    </tr>
153    <tr>
154        <td><code>res/xml/</code></td>
155        <td>Arbitrary XML files that are compiled and can be read at run time by
156            calling {@link android.content.res.Resources#getXml(int) Resources.getXML()}.</td>
157    </tr>
158    <tr>
159        <td><code>res/raw/</code></td>
160        <td>Arbitrary files to copy directly to the device. They are added uncompiled
161            to the compressed file that your application build produces. To use these
162            resources in your application, call {@link android.content.res.Resources#openRawResource(int)
163            Resources.openRawResource()} with the resource ID, which is R.raw.<em>somefilename</em>.</td>
164    </tr>
165</table>
166<p>Resources are compiled into the final APK file. Android creates a wrapper class,
167    called R, that you can use to refer to these resources in your code. R contains subclasses
168    named according to the path and file name of the source file</p>
169<a name="colorvals" id="colorvals"></a>
170<h3>Global Resource Notes</h3>
171<ul>
172    <li>Several resources allow you to define colors. Android accepts color values
173        written in various web-style formats -- a hexadecimal constant in any of the
174        following forms: #RGB, #ARGB, #RRGGBB, #AARRGGBB. </li>
175    <li>All color values support setting an alpha channel value, where the first
176        two hexadecimal numbers specify the transparency. Zero in the alpha channel
177        means transparent. The default value is opaque. </li>
178</ul>
179<a name="UsingResources" id="UsingResources"></a>
180<h2>Using Resources </h2>
181<p>This section describes how to use the resources you've created. It includes the
182    following topics:</p>
183<ul>
184    <li><a href="#ResourcesInCode">Using resources in code</a>&nbsp;- How to call
185        resources in your code to instantiate them. </li>
186    <li><a href="#ReferencesToResources">Referring to resources from other resources</a> &nbsp;-
187        You can reference resources from other resources. This lets you reuse common 
188        resource values inside resources. </li>
189    <li><a href="#AlternateResources">Supporting Alternate Resources for Alternate
190            Configurations</a> - You can specify different resources
191            to load, depending on the language or display configuration of the host
192            hardware. </li>
193</ul>
194<p>At compile time, Android generates a class named R that contains resource identifiers
195    to all the resources in your program. This class contains several subclasses,
196    one for each type of resource supported by Android, and for which you provided
197    a resource file. Each class contains one or more identifiers for the compiled resources,
198    that you use in your code to load the resource. Here is a small resource file
199    that contains string, layout (screens or parts of screens), and image resources.</p>
200<p class="note"><strong>Note:</strong> the R class is an auto-generated file and is not
201designed to be edited by hand. It will be automatically re-created as needed when
202the resources are updated.</p>
203<pre class="prettyprint">package com.android.samples;
204public final class R {
205    public static final class string {
206        public static final int greeting=0x0204000e;
207        public static final int start_button_text=0x02040001;
208        public static final int submit_button_text=0x02040008;
209        public static final int main_screen_title=0x0204000a;
210    };
211    public static final class layout {
212        public static final int start_screen=0x02070000;
213        public static final int new_user_pane=0x02070001;
214        public static final int select_user_list=0x02070002;
215
216    };
217    public static final class drawable {
218        public static final int company_logo=0x02020005;
219        public static final int smiling_cat=0x02020006;
220        public static final int yellow_fade_background=0x02020007;
221        public static final int stretch_button_1=0x02020008;
222
223    };
224};
225</pre>
226<a name="ResourcesInCode" id="ResourcesInCode"></a>
227<h3>Using Resources in Code </h3>
228
229<p>Using resources in code is just a matter of knowing the full resource ID
230and what type of object your resource has been compiled into. Here is the
231syntax for referring to a resource:</p>
232<p><code>R.<em>resource_type</em>.<em>resource_name</em></code></p>
233<p>or</p>
234<p><code>android.R.<em>resource_type</em>.<em>resource_name</em></code></p>
235
236<p>Where <code>resource_type</code> is the R subclass that holds a specific type
237of resource. <code>resource_name</code> is the <em>name</em> attribute for resources
238defined in XML files, or the file name (without the extension) for resources
239defined by other file types. Each type of resource will be added to a specific
240R subclass, depending on the type of resource it is; to learn which R subclass
241hosts your compiled resource type, consult the 
242<a href="available-resources.html">Available Resources</a> document. Resources compiled by your own application can
243be referred to without a package name (simply as
244<code>R.<em>resource_type</em>.<em>resource_name</em></code>). Android contains
245a number of standard resources, such as screen styles and button backgrounds. To
246refer to these in code, you must qualify them with <code>android</code>, as in
247<code>android.R.drawable.button_background</code>.</p>
248
249<p>Here are some good and bad examples of using compiled resources in code:</p>
250
251<pre class="prettyprint">// Load a background for the current screen from a drawable resource.
252this.getWindow().setBackgroundDrawableResource(R.drawable.my_background_image);
253
254// WRONG Sending a string resource reference into a 
255// method that expects a string.
256this.getWindow().setTitle(R.string.main_title);
257
258// RIGHT Need to get the title from the Resources wrapper.
259this.getWindow().setTitle(Resources.getText(R.string.main_title));
260
261// Load a custom layout for the current screen.
262setContentView(R.layout.main_screen);
263
264// Set a slide in animation for a ViewFlipper object.
265mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 
266        R.anim.hyperspace_in));
267
268// Set the text on a TextView object.
269TextView msgTextView = (TextView)findViewByID(R.id.msg);
270msgTextView.setText(R.string.hello_message); </pre>
271
272<a name="ReferencesToResources" id="ReferencesToResources"></a>
273<h3>References to Resources</h3>
274
275<p>A value supplied in an attribute (or resource) can also be a reference to
276a resource.  This is often used in layout files to supply strings (so they
277can be localized) and images (which exist in another file), though a reference
278can be any resource type including colors and integers.</p>
279
280<p>For example, if we have 
281<a href="available-resources.html#colordrawableresources">color 
282resources</a>, we can write a layout file that sets the text color size to be
283the value contained in one of those resources:</p>
284
285<pre>
286&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
287&lt;EditText id=&quot;text&quot;
288    xmlns:android=&quot;http://schemas.android.com/apk/res/android";
289    android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;
290    <strong>android:textColor=&quot;&#64;color/opaque_red&quot;</strong>
291    android:text=&quot;Hello, World!&quot; /&gt;
292</pre>
293
294<p>Note here the use of the '@' prefix to introduce a resource reference -- the
295text following that is the name of a resource in the form
296of <code>@[package:]type/name</code>.  In this case we didn't need to specify
297the package because we are referencing a resource in our own package.  To
298reference a system resource, you would need to write:</p>
299
300<pre>
301&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
302&lt;EditText id=&quot;text&quot;
303    xmlns:android=&quot;http://schemas.android.com/apk/res/android";
304    android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;
305    android:textColor=&quot;&#64;<strong>android:</strong>color/opaque_red&quot;
306    android:text=&quot;Hello, World!&quot; /&gt;
307</pre>
308
309<p>As another example, you should always use resource references when supplying
310strings in a layout file so that they can be localized:</p>
311
312<pre>
313&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
314&lt;EditText id=&quot;text&quot;
315    xmlns:android=&quot;http://schemas.android.com/apk/res/android";
316    android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;
317    android:textColor=&quot;&#64;android:color/opaque_red&quot;
318    android:text=&quot;&#64;string/hello_world&quot; /&gt;
319</pre>
320
321<p>This facility can also be used to create references between resources.
322For example, we can create new drawable resources that are aliases for
323existing images:</p>
324
325<pre>
326&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
327&lt;resources&gt;
328    &lt;drawable id=&quot;my_background&quot;&gt;&#64;android:drawable/theme2_background&lt;/drawable&gt;
329&lt;/resources&gt;
330</pre>
331
332<a name="ReferencesToThemeAttributes"></a>
333<h3>References to Theme Attributes</h3>
334
335<p>Another kind of resource value allows you to reference the value of an
336attribute in the current theme.  This attribute reference can <em>only</em>
337be used in style resources and XML attributes; it allows you to customize the
338look of UI elements by changing them to standard variations supplied by the
339current theme, instead of supplying more concrete values.</p>
340
341<p>As an example, we can use this in our layout to set the text color to
342one of the standard colors defined in the base system theme:</p>
343
344<pre>
345&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
346&lt;EditText id=&quot;text&quot;
347    xmlns:android=&quot;http://schemas.android.com/apk/res/android";
348    android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;
349    <strong>android:textColor=&quot;?android:textDisabledColor&quot;</strong>
350    android:text=&quot;&#64;string/hello_world&quot; /&gt;
351</pre>
352
353<p>Note that this is very similar to a resource reference, except we are using
354an '?' prefix instead of '@'.  When you use this markup, you are supplying
355the name of an attribute resource that will be looked up in the theme --
356because the resource tool knows that an attribute resource is expected,
357you do not need to explicitly state the type (which would be
358<code>?android:attr/android:textDisabledColor</code>).</p>
359
360<p>Other than using this resource identifier to find the value in the
361theme instead of raw resources, the name syntax is identical to the '@' format:
362<code>?[namespace:]type/name</code> with the type here being optional.</p>
363
364<a name="UsingSystemResources"></a>
365<h3>Using System Resources</h3>
366
367<p>Many resources included with the system are available to applications.
368All such resources are defined under the class "android.R".  For example,
369you can display the standard application icon in a screen with the following
370code:</p>
371
372<pre class="prettyprint">
373public class MyActivity extends Activity
374{
375    public void onStart() 
376    {
377        requestScreenFeatures(FEATURE_BADGE_IMAGE);
378
379        super.onStart();
380
381        setBadgeResource(android.R.drawable.sym_def_app_icon);
382    }
383}
384</pre>
385
386<p>In a similar way, this code will apply to your screen the standard
387"green background" visual treatment defined by the system:</p>
388
389<pre class="prettyprint">
390public class MyActivity extends Activity
391{
392    public void onStart() 
393    {
394        super.onStart();
395
396        setTheme(android.R.style.Theme_Black);
397    }
398}
399</pre>
400
401<a name="AlternateResources" id="AlternateResources"></a>
402<h2>Alternate Resources (for alternate languages and configurations)</h2>
403
404<p>You can supply different resources for your product according to the UI
405language or hardware configuration on the device. Note that although you can
406include different string, layout, and other resources, the SDK does not expose
407methods to let you specify which alternate resource set to load. Android
408detects the proper set for the hardware and location, and loads them as
409appropriate. Users can select alternate language settings using the settings
410panel on the device. </p>
411<p>To include alternate resources, create parallel resource folders with
412qualifiers appended to the folder names, indicating the configuration it
413applies to (language, screen orientation, and so on). For example, here is a
414project that holds one string resource file for English, and another for
415French:</p>
416
417<pre>
418MyApp/
419    res/
420        values-en/
421            strings.xml
422        values-fr/
423            strings.xml
424</pre>
425
426<p>Android supports several types of qualifiers, with various values for each.
427Append these to the end of the resource folder name, separated by dashes. You
428can add multiple qualifiers to each folder name, but they must appear in the
429order they are listed here. For example, a folder containing drawable
430resources for a fully specified configuration would look like:</p>
431
432<pre>
433MyApp/
434    res/
435        drawable-en-rUS-port-160dpi-finger-keysexposed-qwerty-dpad-480x320/
436</pre>
437
438<p>More typically, you will only specify a few specific configuration options
439that a resource is defined for. You may drop any of the values from the
440complete list, as long as the remaining values are still in the same
441order:</p>
442
443<pre>
444MyApp/
445    res/
446        drawable-en-rUS-finger/
447        drawable-port/
448        drawable-port-160dpi/
449        drawable-qwerty/
450</pre>
451
452<table border="1">
453    <tr>
454        <th> Qualifier </th>
455        <th> Values </th>
456    </tr>
457    <tr>
458        <td>Language</td>
459        <td>The two letter <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
460                639-1</a> language code in lowercase. For example: 
461                <code>en</code>, <code>fr</code>, <code>es</code> </td>
462    </tr>
463    <tr>
464        <td>Region</td>
465        <td>The two letter
466        <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
467                3166-1-alpha-2</a> language code in uppercase preceded by a lowercase
468            &quot;r&quot;. For example: <code>rUS</code>, <code>rFR</code>, <code>rES</code></td>
469    </tr>
470    <tr>
471        <td>Screen orientation</td>
472        <td><code>port</code>, <code>land</code>, <code>square</code> </td>
473    </tr>
474    <tr>
475        <td>Screen pixel density</td>
476        <td><code>92dpi</code>, <code>108dpi</code>, etc. </td>
477    </tr>
478    <tr>
479        <td>Touchscreen type</td>
480        <td><code>notouch</code>, <code>stylus</code>, <code>finger</code></td>
481    </tr>
482    <tr>
483        <td>Whether the keyboard is available to the user</td>
484        <td><code>keysexposed</code>, <code>keyshidden</code> </td>
485    </tr>
486    <tr>
487        <td>Primary text input method</td>
488        <td><code>nokeys</code>, <code>qwerty</code>, <code>12key</code> </td>
489    </tr>
490    <tr>
491        <td>Primary non-touchscreen<br />
492            navigation method</td>
493        <td><code>nonav</code>, <code>dpad</code>, <code>trackball</code>, <code>wheel</code> </td>
494    </tr>
495    <tr>
496        <td>Screen dimensions</td>
497        <td><code>320x240</code>, <code>640x480</code>, etc. The larger dimension
498            must be specified first. </td>
499    </tr>
500</table>
501
502<p>This list does not include device-specific parameters such as carrier,
503branding, device/hardware, or manufacturer. Everything that an application
504needs to know about the device that it is running on is encoded via the
505resource qualifiers in the table above.</p>
506
507<p>Here are some general guidelines on qualified resource directory names:</p>
508
509<ul>
510    <li>Values are separated by a dash (as well as a dash after the base directory
511        name) </li>
512    <li>Values are case-sensitive (even though they must be unique across all folder
513        names in a case-insensitive way)<br />For example,</li>
514    <ul>
515        <li>A portrait-specific <code>drawable</code> directory must be named
516            <code>drawable-port</code>, not <code>drawable-PORT</code>.</li>
517        <li>You may not have two directories named <code>drawable-port</code>
518            and <code>drawable-PORT</code>, even if you had intended "port" and
519            "PORT" to refer to different parameter values.</li>
520    </ul>
521    <li>Only one value for each qualifier type is supported (that is, you cannot
522        specify <code>drawable-rEN-rFR/</code>)</li>
523    <li>You can specify multiple parameters to define specific configurations,
524        but they must always be in the order listed above.
525        For example, <code>drawable-en-rUS-land</code> will apply to landscape view,
526        US-English devices. </li>
527    <li>Android will try to find the most specific matching directory for the current
528        configuration, as described below</li>
529    <li>The order of parameters listed in this table is used to break a tie in case
530        of multiple qualified directories (see the example given below) </li>
531    <li>All directories, both qualified and unqualified, live under the <code>res/</code> folder.
532        Qualified directories cannot be nested (you cannot have <code>res/drawable/drawable-en</code>) </li>
533    <li>All resources will be referenced in code or resource reference syntax by
534        their simple, undecorated name. So if a resource is named this:<br />
535        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>MyApp/res/drawable-port-92dp/myimage.png</code><br />
536        It would be referenced as this:<br />
537        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>R.drawable.myimage</code> (code)<br />
538        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>&#064;drawable/myimage</code> (XML)</li>
539</ul>
540
541<h3>How Android finds the best matching directory </h3>
542
543<p>Android will pick which of the various underlying resource files should be
544used at runtime, depending on the current configuration. The selection process
545is as follows:</p>
546
547<ol>
548    <li>
549            Eliminate any resources whose configuration does not match the current
550            device configuration. For example, if the screen pixel density is 108dpi,
551            this would eliminate only <code>MyApp/res/drawable-port-92dpi/</code>.
552        <blockquote>
553            <pre>
554MyApp/res/drawable/myimage.png
555MyApp/res/drawable-en/myimage.png
556MyApp/res/drawable-port/myimage.png
557<strike>MyApp/res/drawable-port-92dpi/myimage.png</strike>
558</pre>
559        </blockquote>
560    </li>
561    <li>
562            Pick the resources with the highest number of matching configurations.
563            For example, if our locale is en-GB and orientation is port, then we
564            have two candidates with one matching configuration each: 
565            <code>MyApp/res/drawable-en/</code> and <code>MyApp/res/drawable-port/</code>.
566            The directory <code>MyApp/res/drawable/</code> is eliminated because
567            it has zero matching configurations, while the others have one matching
568            configuration.
569        <blockquote>
570            <pre>
571<strike>MyApp/res/drawable/myimage.png</strike>
572MyApp/res/drawable-en/myimage.png
573MyApp/res/drawable-port/myimage.png
574</pre>
575        </blockquote>
576    </li>
577    <li>
578            Pick the final matching file based on configuration precedence, which
579            is the order of parameters listed in the table above. That is, it is
580            more important to match the language than the orientation, so we break
581            the tie by picking the language-specific file, <code>MyApp/res/drawable-en/</code>.
582        <blockquote>
583            <pre>MyApp/res/drawable-en/myimage.png
584<strike>MyApp/res/drawable-port/myimage.png</strike>
585</pre>
586        </blockquote>
587    </li>
588</ol>
589
590<a name="ResourcesTerminology"></a>
591<h2>Terminology</h2>
592
593<p>The resource system brings a number of different pieces together to
594form the final complete resource functionality.  To help understand the
595overall system, here are some brief definitions of the core concepts and
596components you will encounter in using it:</p>
597
598<p><strong>Asset</strong>: A single blob of data associated with an application. This
599includes object files compiled from the Java source code, graphics (such as PNG
600images), XML files, etc. These files are organized in a directory hierarchy
601that, during final packaging of the application, is bundled together into a
602single ZIP file.</p>
603
604<p><strong>aapt</strong>: Android Asset Packaging Tool. The tool that generates the 
605final ZIP file of application assets.  In addition to collecting raw assets 
606together, it also parses resource definitions into binary asset data.</p>
607
608<p><strong>Resource Table</strong>: A special asset that aapt generates for you,
609describing all of the resources contained in an application/package.
610This file is accessed for you by the Resources class; it is not touched
611directly by applications.</p>
612
613<p><strong>Resource</strong>: An entry in the Resource Table describing a single
614named value.  Broadly, there are two types of resources: primitives and
615bags.</p>
616
617<p><strong>Resource Identifier</strong>: In the Resource Table all resources are
618identified by a unique integer number.  In source code (resource descriptions,
619XML files, Java source code) you can use symbolic names that stand as constants for
620the actual resource identifier integer.</p>
621
622<p><strong>Primitive Resource</strong>: All primitive resources can be written as a
623simple string, using formatting to describe a variety of primitive types
624included in the resource system: integers, colors, strings, references to
625other resources, etc.  Complex resources, such as bitmaps and XML
626describes, are stored as a primitive string resource whose value is the path
627of the underlying Asset holding its actual data.</p>
628
629<p><strong>Bag Resource</strong>: A special kind of resource entry that, instead of a
630simple string, holds an arbitrary list of name/value pairs.  Each name is
631itself a resource identifier, and each value can hold
632the same kinds of string formatted data as a normal resource.  Bags also
633support inheritance: a bag can inherit the values from another bag, selectively
634replacing or extending them to generate its own contents.</p>
635
636<p><strong>Kind</strong>: The resource kind is a way to organize resource identifiers
637for various purposes.  For example, drawable resources are used to
638instantiate Drawable objects, so their data is a primitive resource containing
639either a color constant or string path to a bitmap or XML asset.  Other
640common resource kinds are string (localized string primitives), color
641(color primitives), layout (a string path to an XML asset describing a view
642layout), and style (a bag resource describing user interface attributes).
643There is also a standard "attr" resource kind, which defines the resource
644identifiers to be used for naming bag items and XML attributes</p>
645
646<p><strong>Style</strong>: The name of the resource kind containing bags that are used
647to supply a set of user interface attributes.  For example, a TextView class may
648be given a style resource that defines its text size, color, and alignment.
649In a layout XML file, you associate a style with a bag using the "style"
650attribute, whose value is the name of the style resource.</p>
651
652<p><strong>Style Class</strong>: Specifies a related set of attribute resources.
653This data is not placed in the resource table itself, but used to generate
654constants in the source code that make it easier for you to retrieve values out of
655a style resource and/or XML tag's attributes.  For example, the
656Android platform defines a "View" style class that
657contains all of the standard view attributes: padding, visibility,
658background, etc.; when View is inflated it uses this style class to
659retrieve those values from the XML file (at which point style and theme
660information is applied as approriate) and load them into its instance.</p>
661
662<p><strong>Configuration</strong>: For any particular resource identifier, there may be
663multiple different available values depending on the current configuration.
664The configuration includes the locale (language and country), screen
665orientation, screen density, etc.  The current configuration is used to
666select which resource values are in effect when the resource table is
667loaded.</p>
668
669<p><strong>Theme</strong>: A standard style resource that supplies global
670attribute values for a particular context.  For example, when writing an
671Activity the application developer can select a standard theme to use, such
672as the Theme.White or Theme.Black styles; this style supplies information
673such as the screen background image/color, default text color, button style,
674text editor style, text size, etc.  When inflating a layout resource, most
675values for widgets (the text color, selector, background) if not explicitly
676set will come from the current theme; style and attribute
677values supplied in the layout can also assign their value from explicitly
678named values in the theme attributes if desired.</p>
679
680<p><strong>Overlay</strong>: A resource table that does not define a new set of resources,
681but instead replaces the values of resources that are in another resource table.
682Like a configuration, this is applied at load time
683to the resource data; it can add new configuration values (for example
684strings in a new locale), replace existing values (for example change
685the standard white background image to a "Hello Kitty" background image),
686and modify resource bags (for example change the font size of the Theme.White
687style to have an 18 pt font size).  This is the facility that allows the
688user to select between different global appearances of their device, or
689download files with new appearances.</p>
690
691<h2>Resource Reference</h2>
692<p>The <a href="available-resources.html">Available Resources</a>
693document provides a detailed list of the various types of resource and how to use them
694from within the Java source code, or from other references.</p>
695
696<a name="i18n" id="i18n"></a>
697<h2>Internationalization and Localization</h2>
698<p class="note"><strong>Coming Soon:</strong> Internationalization and Localization are
699critical, but are also not quite ready yet in the current SDK. As the
700SDK matures, this section will contain information on the Internationalization
701and Localization features of the Android platform. In the meantime, it is a good
702idea to start by externalizing all strings, and practicing good structure in
703creating and using resources.</p>
704
705