providing-resources.jd revision 22d17c984ae91e85a67d3fc03c092538c5080b0f
1page.title=Providing Resources
2parent.title=Application Resources
3parent.link=index.html
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8  <h2>Quickview</h2>
9  <ul>
10    <li>Different types of resources belong in different subdirectories of {@code res/}</li>
11    <li>Alternative resources provide configuration-specific resource files</li>
12    <li>Always include default resources so your app does not depend on specific
13device configurations</li>
14  </ul>
15  <h2>In this document</h2>
16  <ol>
17    <li><a href="#ResourceTypes">Grouping Resource Types</a></li>
18    <li><a href="#AlternativeResources">Providing Alternative Resources</a>
19      <ol>
20        <li><a href="#QualifierRules">Qualifier name rules</a></li>
21        <li><a href="#AliasResources">Creating alias resources</a></li>
22      </ol>
23    </li>
24    <li><a href="#Compatibility">Providing the Best Device Compatibility with Resources</a>
25      <ol>
26        <li><a href="#ScreenCompatibility">Providing screen resource compatibility for Android
271.5</a></li>
28      </ol>
29    </li>
30    <li><a href="#BestMatch">How Android Finds the Best-matching Resource</a></li>
31    <li><a href="#KnownIssues">Known Issues</a></li>
32  </ol>
33
34  <h2>See also</h2>
35  <ol>
36    <li><a href="accessing-resources.html">Accessing Resources</a></li>
37    <li><a href="available-resources.html">Resource Types</a></li>
38    <li><a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
39Screens</a></li>
40  </ol>
41</div>
42</div>
43
44<p>You should always externalize application resources such as images and strings from your
45code, so that you can maintain them independently. You should also provide alternative resources for
46specific device configurations, by grouping them in specially-named resource directories. At
47runtime, Android uses the appropriate resource based on the current configuration. For
48example, you might want to provide a different UI layout depending on the screen size or different
49strings depending on the language setting.</p>
50
51<p>Once you externalize your application resources, you can access them
52using resource IDs that are generated in your project's {@code R} class. How to use
53resources in your application is discussed in <a href="accessing-resources.html">Accessing
54Resources</a>. This document shows you how to group your resources in your Android project and
55provide alternative resources for specific device configurations.</p>
56
57
58<h2 id="ResourceTypes">Grouping Resource Types</h2>
59
60<p>You should place each type of resource in a specific subdirectory of your project's
61{@code res/} directory. For example, here's the file hierarchy for a simple project:</p>
62
63<pre class="classic no-pretty-print">
64MyProject/
65    src/  <span style="color:black">
66        MyActivity.java  </span>
67    res/
68        drawable/  <span style="color:black">
69            icon.png  </span>
70        layout/  <span style="color:black">
71            main.xml
72            info.xml</span>
73        values/  <span style="color:black">
74            strings.xml  </span>
75</pre>
76
77<p>As you can see in this example, the {@code res/} directory contains all the resources (in
78subdirectories): an image resource, two layout resources, and a string resource file. The resource
79directory names are important and are described in table 1.</p>
80
81<p class="table-caption" id="table1"><strong>Table 1.</strong> Resource directories
82supported inside project {@code res/} directory.</p>
83
84<table>
85  <tr>
86    <th scope="col">Directory</th>
87    <th scope="col">Resource Type</th>
88  </tr>
89
90  <tr>
91    <td><code>animator/</code></td>
92    <td>XML files that define <a href="{@docRoot}guide/topics/graphics/prop-animation.html">property
93animations</a>.</td>
94  </tr>
95
96  <tr>
97    <td><code>anim/</code></td>
98    <td>XML files that define <a
99href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">tween
100animations</a>. (Property animations can also be saved in this directory, but
101the {@code animator/} directory is preferred for property animations to distinguish between the two
102types.)</td>
103  </tr>
104
105  <tr>
106    <td><code>color/</code></td>
107    <td>XML files that define a state list of colors. See <a href="color-list-resource.html">Color
108State List Resource</a></td>
109  </tr>
110
111  <tr>
112    <td><code>drawable/</code></td>
113    <td><p>Bitmap files ({@code .png}, {@code .9.png}, {@code .jpg}, {@code .gif}) or XML files that
114are compiled into the following drawable resource subtypes:</p>
115      <ul>
116        <li>Bitmap files</li>
117        <li>Nine-Patches (re-sizable bitmaps)</li>
118        <li>State lists</li>
119        <li>Shapes</li>
120        <li>Animation drawables</li>
121        <li>Other drawables</li>
122      </ul>
123      <p>See <a href="drawable-resource.html">Drawable Resources</a>.</p>
124    </td>
125  </tr>
126
127  <tr>
128    <td><code>layout/</code></td>
129    <td>XML files that define a user interface layout.
130        See <a href="layout-resource.html">Layout Resource</a>.</td>
131  </tr>
132
133  <tr>
134    <td><code>menu/</code></td>
135    <td>XML files that define application menus, such as an Options Menu, Context Menu, or Sub
136Menu. See <a href="menu-resource.html">Menu Resource</a>.</td>
137  </tr>
138
139  <tr>
140    <td><code>raw/</code></td>
141    <td><p>Arbitrary files to save in their raw form. To open these resources with a raw
142{@link java.io.InputStream}, call {@link android.content.res.Resources#openRawResource(int)
143Resources.openRawResource()} with the resource ID, which is {@code R.raw.<em>filename</em>}.</p>
144      <p>However, if you need access to original file names and file hierarchy, you might consider
145saving some resources in the {@code
146assets/} directory (instead of {@code res/raw/}). Files in {@code assets/} are not given a
147resource ID, so you can read them only using {@link android.content.res.AssetManager}.</p></td>
148  </tr>
149
150  <tr>
151    <td><code>values/</code></td>
152    <td><p>XML files that contain simple values, such as strings, integers, and colors.</p>
153      <p>Whereas XML resource files in other {@code res/} subdirectories define a single resource
154based on the XML filename, files in the {@code values/} directory describe multiple resources.
155For a file in this directory, each child of the {@code &lt;resources&gt;} element defines a single
156resource. For example, a {@code &lt;string&gt;} element creates an
157{@code R.string} resource and a  {@code &lt;color&gt;} element creates an {@code R.color}
158resource.</p>
159      <p>Because each resource is defined with its own XML element, you can name the file
160whatever you want and place different resource types in one file. However, for clarity, you might
161want to place unique resource types in different files. For example, here are some filename
162conventions for resources you can create in this directory:</p>
163      <ul>
164        <li>arrays.xml for resource arrays (<a
165href="more-resources.html#TypedArray">typed arrays</a>).</li>
166        <li>colors.xml for <a
167href="more-resources.html#Color">color values</a></li>
168        <li>dimens.xml for <a
169href="more-resources.html#Dimension">dimension values</a>.</li>
170        <li>strings.xml for <a href="string-resource.html">string
171values</a>.</li>
172        <li>styles.xml for <a href="style-resource.html">styles</a>.</li>
173      </ul>
174      <p>See <a href="string-resource.html">String Resources</a>,
175        <a href="style-resource.html">Style Resource</a>, and
176        <a href="more-resources.html">More Resource Types</a>.</p>
177    </td>
178  </tr>
179
180  <tr>
181    <td><code>xml/</code></td>
182    <td>Arbitrary XML files that can be read at runtime by calling {@link
183android.content.res.Resources#getXml(int) Resources.getXML()}. Various XML configuration files
184must be saved here, such as a <a
185href="{@docRoot}guide/topics/search/searchable-config.html">searchable configuration</a>.
186<!-- or preferences configuration. --></td>
187  </tr>
188</table>
189
190<p class="caution"><strong>Caution:</strong> Never save resource files directly inside the
191{@code res/} directory&mdash;it will cause a compiler error.</p>
192
193<p>For more information about certain types of resources, see the <a
194href="available-resources.html">Resource Types</a> documentation.</p>
195
196<p>The resources that you save in the subdirectories defined in table 1 are your "default"
197resources. That is, these resources define the default design and content for your application.
198However, different types of Android-powered devices might call for different types of resources.
199For example, if a device has a larger than normal screen, then you should provide
200different layout resources that take advantage of the extra screen space. Or, if a device has a
201different language setting, then you should provide different string resources that translate the
202text in your user interface. To provide these different resources for different device
203configurations, you need to provide alternative resources, in addition to your default
204resources.</p>
205
206
207<h2 id="AlternativeResources">Providing Alternative Resources</h2>
208
209
210<div class="figure" style="width:429px">
211<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="167" alt="" />
212<p class="img-caption">
213<strong>Figure 1.</strong> Two different devices, each using different layout resources.</p>
214</div>
215
216<p>Almost every application should provide alternative resources to support specific device
217configurations. For instance, you should include alternative drawable resources for different
218screen densities and alternative string resources for different languages. At runtime, Android
219detects the current device configuration and loads the appropriate
220resources for your application.</p>
221
222<p>To specify configuration-specific alternatives for a set of resources:</p>
223<ol>
224  <li>Create a new directory in {@code res/} named in the form {@code
225<em>&lt;resources_name&gt;</em>-<em>&lt;config_qualifier&gt;</em>}.
226    <ul>
227      <li><em>{@code &lt;resources_name&gt;}</em> is the directory name of the corresponding default
228resources (defined in table 1).</li>
229      <li><em>{@code &lt;qualifier&gt;}</em> is a name that specifies an individual configuration
230for which these resources are to be used (defined in table 2).</li>
231    </ul>
232    <p>You can append more than one <em>{@code &lt;qualifier&gt;}</em>. Separate each
233one with a dash.</p>
234    <p class="caution"><strong>Caution:</strong> When appending multiple qualifiers, you must
235place them in the same order in which they are listed in table 2. If the qualifiers are ordered
236wrong, the resources are ignored.</p>
237  </li>
238  <li>Save the respective alternative resources in this new directory. The resource files must be
239named exactly the same as the default resource files.</li>
240</ol>
241
242<p>For example, here are some default and alternative resources:</p>
243
244<pre class="classic no-pretty-print">
245res/
246    drawable/   <span style="color:black">
247        icon.png
248        background.png    </span>
249    drawable-hdpi/  <span style="color:black">
250        icon.png
251        background.png  </span>
252</pre>
253
254<p>The {@code hdpi} qualifier indicates that the resources in that directory are for devices with a
255high-density screen. The images in each of these drawable directories are sized for a specific
256screen density, but the filenames are exactly
257the same. This way, the resource ID that you use to reference the {@code icon.png} or {@code
258background.png} image is always the same, but Android selects the
259version of each resource that best matches the current device, by comparing the device
260configuration information with the qualifiers in the resource directory name.</p>
261
262<p>Android supports several configuration qualifiers and you can
263add multiple qualifiers to one directory name, by separating each qualifier with a dash. Table 2
264lists the valid configuration qualifiers, in order of precedence&mdash;if you use multiple
265qualifiers for a resource directory, you must add them to the directory name in the order they
266are listed in the table.</p>
267
268
269<p class="table-caption" id="table2"><strong>Table 2.</strong> Configuration qualifier
270names.</p>
271<table>
272    <tr>
273        <th>Configuration</th>
274        <th>Qualifier Values</th>
275        <th>Description</th>
276    </tr>
277    <tr id="MccQualifier">
278      <td>MCC and MNC</td>
279      <td>Examples:<br/>
280        <code>mcc310</code><br/>
281        <code><nobr>mcc310-mnc004</nobr></code><br/>
282        <code>mcc208-mnc00</code><br/>
283        etc.
284      </td>
285      <td>
286        <p>The mobile country code (MCC), optionally followed by mobile network code (MNC)
287        from the SIM card in the device. For example, <code>mcc310</code> is U.S. on any carrier,
288        <code>mcc310-mnc004</code> is U.S. on Verizon, and <code>mcc208-mnc00</code> is France on
289        Orange.</p>
290        <p>If the device uses a radio connection (GSM phone), the MCC and MNC values come
291        from the SIM card.</p>
292        <p>You can also use the MCC alone (for example, to include country-specific legal
293resources in your application). If you need to specify based on the language only, then use the
294<em>language and region</em> qualifier instead (discussed next). If you decide to use the MCC and
295MNC qualifier, you should do so with care and test that it works as expected.</p>
296        <p>Also see the configuration fields {@link
297android.content.res.Configuration#mcc}, and {@link
298android.content.res.Configuration#mnc}, which indicate the current mobile country code
299and mobile network code, respectively.</p>
300      </td>
301    </tr>
302    <tr id="LocaleQualifier">
303      <td>Language and region</td>
304      <td>Examples:<br/>
305        <code>en</code><br/>
306        <code>fr</code><br/>
307        <code>en-rUS</code><br/>
308        <code>fr-rFR</code><br/>
309        <code>fr-rCA</code><br/>
310        etc.
311      </td>
312      <td><p>The language is defined by a two-letter <a
313href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
314              639-1</a> language code, optionally followed by a two letter
315              <a
316href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
317              3166-1-alpha-2</a> region code (preceded by lowercase &quot;{@code r}&quot;).
318        </p><p>
319        The codes are <em>not</em> case-sensitive; the {@code r} prefix is used to
320        distinguish the region portion.
321        You cannot specify a region alone.</p>
322        <p>This can change during the life
323of your application if the user changes his or her language in the system settings. See <a
324href="runtime-changes.html">Handling Runtime Changes</a> for information about
325how this can affect your application during runtime.</p>
326        <p>See <a href="localization.html">Localization</a> for a complete guide to localizing
327your application for other languages.</p>
328        <p>Also see the {@link android.content.res.Configuration#locale} configuration field, which
329indicates the current locale.</p>
330      </td>
331    </tr>
332    <tr id="LayoutDirectionQualifier">
333      <td>Layout Direction</td>
334      <td><code>ldrtl</code><br/>
335        <code>ldltr</code><br/>
336      </td>
337      <td><p>The layout direction of your application. {@code ldrtl} means "layout-direction-right-to-left".
338      {@code ldltr} means "layout-direction-left-to-right" and is the default implicit value.
339      </p>
340      <p>This can apply to any resource such as layouts, drawables, or values.
341      </p>
342      <p>For example, if you want to provide some specific layout for the Arabic language and some
343      generic layout for any other "right-to-left" language (like Persian or Hebrew) then you would have:
344      </p>
345<pre class="classic no-pretty-print">
346res/
347    layout/   <span style="color:black">
348        main.xml  </span>(Default layout)
349    layout-ar/  <span style="color:black">
350        main.xml  </span>(Specific layout for Arabic)
351    layout-ldrtl/  <span style="color:black">
352        main.xml  </span>(Any "right-to-left" language, except
353                  for Arabic, because the "ar" language qualifier
354                  has a higher precedence.)
355</pre>
356        <p class="note"><strong>Note:</strong> To enable right-to-left layout features
357        for your app, you must set <a
358        href="{@docRoot}guide/topics/manifest/application-element.html#supportsrtl">{@code
359        supportsRtl}</a> to {@code "true"} and set <a
360        href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target"
361        >{@code targetSdkVersion}</a> to 17 or higher.</p>
362        <p><em>Added in API level 17.</em></p>
363      </td>
364    </tr>
365    <tr id="SmallestScreenWidthQualifier">
366      <td>smallestWidth</td>
367      <td><code>sw&lt;N&gt;dp</code><br/><br/>
368        Examples:<br/>
369        <code>sw320dp</code><br/>
370        <code>sw600dp</code><br/>
371        <code>sw720dp</code><br/>
372        etc.
373      </td>
374      <td>
375        <p>The fundamental size of a screen, as indicated by the shortest dimension of the available
376screen area. Specifically, the device's smallestWidth is the shortest of the screen's available
377height and width (you may also think of it as the "smallest possible width" for the screen). You can
378use this qualifier to ensure that, regardless of the screen's current orientation, your
379application's has at least {@code &lt;N&gt;} dps of width available for it UI.</p>
380        <p>For example, if your layout requires that its smallest dimension of screen area be at
381least 600 dp at all times, then you can use this qualifer to create the layout resources, {@code
382res/layout-sw600dp/}. The system will use these resources only when the smallest dimension of
383available screen is at least 600dp, regardless of whether the 600dp side is the user-perceived
384height or width. The smallestWidth is a fixed screen size characteristic of the device; <strong>the
385device's smallestWidth does not change when the screen's orientation changes</strong>.</p>
386        <p>The smallestWidth of a device takes into account screen decorations and system UI. For
387example, if the device has some persistent UI elements on the screen that account for space along
388the axis of the smallestWidth, the system declares the smallestWidth to be smaller than the actual
389screen size, because those are screen pixels not available for your UI. Thus, the value you use
390should be the actual smallest dimension <em>required by your layout</em> (usually, this value is the
391"smallest width" that your layout supports, regardless of the screen's current orientation).</p>
392        <p>Some values you might use here for common screen sizes:</p>
393        <ul>
394          <li>320, for devices with screen configurations such as:
395            <ul>
396              <li>240x320 ldpi (QVGA handset)</li>
397              <li>320x480 mdpi (handset)</li>
398              <li>480x800 hdpi (high density handset)</li>
399            </ul>
400          </li>
401          <li>480, for screens such as 480x800 mdpi (tablet/handset).</li>
402          <li>600, for screens such as 600x1024 mdpi (7" tablet).</li>
403          <li>720, for screens such as 720x1280 mdpi (10" tablet).</li>
404        </ul>
405        <p>When your application provides multiple resource directories with different values for
406        the smallestWidth qualifier, the system uses the one closest to (without exceeding) the
407device's smallestWidth. </p>
408        <p><em>Added in API level 13.</em></p>
409        <p>Also see the <a
410href="{@docRoot}guide/topics/manifest/supports-screens-element.html#requiresSmallest">{@code
411android:requiresSmallestWidthDp}</a> attribute, which declares the minimum smallestWidth with which
412your application is compatible, and the {@link
413android.content.res.Configuration#smallestScreenWidthDp} configuration field, which holds the
414device's smallestWidth value.</p>
415        <p>For more information about designing for different screens and using this
416qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
417Multiple Screens</a> developer guide.</p>
418      </td>
419    </tr>
420    <tr id="ScreenWidthQualifier">
421      <td>Available width</td>
422      <td><code>w&lt;N&gt;dp</code><br/><br/>
423        Examples:<br/>
424        <code>w720dp</code><br/>
425        <code>w1024dp</code><br/>
426        etc.
427      </td>
428      <td>
429        <p>Specifies a minimum available screen width, in {@code dp} units at which the resource
430          should be used&mdash;defined by the <code>&lt;N&gt;</code> value.  This
431          configuration value will change when the orientation
432          changes between landscape and portrait to match the current actual width.</p>
433        <p>When your application provides multiple resource directories with different values
434          for this configuration, the system uses the one closest to (without exceeding)
435          the device's current screen width.  The
436          value here takes into account screen decorations, so if the device has some
437          persistent UI elements on the left or right edge of the display, it
438          uses a value for the width that is smaller than the real screen size, accounting
439          for these UI elements and reducing the application's available space.</p>
440        <p><em>Added in API level 13.</em></p>
441        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
442          configuration field, which holds the current screen width.</p>
443        <p>For more information about designing for different screens and using this
444qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
445Multiple Screens</a> developer guide.</p>
446      </td>
447    </tr>
448    <tr id="ScreenHeightQualifier">
449      <td>Available height</td>
450      <td><code>h&lt;N&gt;dp</code><br/><br/>
451        Examples:<br/>
452        <code>h720dp</code><br/>
453        <code>h1024dp</code><br/>
454        etc.
455      </td>
456      <td>
457        <p>Specifies a minimum available screen height, in "dp" units at which the resource
458          should be used&mdash;defined by the <code>&lt;N&gt;</code> value.  This
459          configuration value will change when the orientation
460          changes between landscape and portrait to match the current actual height.</p>
461        <p>When your application provides multiple resource directories with different values
462          for this configuration, the system uses the one closest to (without exceeding)
463          the device's current screen height.  The
464          value here takes into account screen decorations, so if the device has some
465          persistent UI elements on the top or bottom edge of the display, it uses
466          a value for the height that is smaller than the real screen size, accounting
467          for these UI elements and reducing the application's available space.  Screen
468          decorations that are not fixed (such as a phone status bar that can be
469          hidden when full screen) are <em>not</em> accounted for here, nor are
470          window decorations like the title bar or action bar, so applications must be prepared to
471          deal with a somewhat smaller space than they specify.
472        <p><em>Added in API level 13.</em></p>
473        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
474          configuration field, which holds the current screen width.</p>
475        <p>For more information about designing for different screens and using this
476qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
477Multiple Screens</a> developer guide.</p>
478      </td>
479    </tr>
480    <tr id="ScreenSizeQualifier">
481      <td>Screen size</td>
482      <td>
483        <code>small</code><br/>
484        <code>normal</code><br/>
485        <code>large</code><br/>
486        <code>xlarge</code>
487      </td>
488      <td>
489        <ul class="nolist">
490        <li>{@code small}: Screens that are of similar size to a
491        low-density QVGA screen. The minimum layout size for a small screen
492        is approximately 320x426 dp units.  Examples are QVGA low density and VGA high
493        density.</li>
494        <li>{@code normal}: Screens that are of similar size to a
495        medium-density HVGA screen. The minimum
496        layout size for a normal screen is approximately 320x470 dp units.  Examples
497        of such screens a WQVGA low density, HVGA medium density, WVGA
498        high density.</li>
499        <li>{@code large}: Screens that are of similar size to a
500        medium-density VGA screen.
501        The minimum layout size for a large screen is approximately 480x640 dp units.
502        Examples are VGA and WVGA medium density screens.</li>
503        <li>{@code xlarge}: Screens that are considerably larger than the traditional
504        medium-density HVGA screen. The minimum layout size for an xlarge screen
505        is approximately 720x960 dp units.  In most cases, devices with extra large
506        screens would be too large to carry in a pocket and would most likely
507        be tablet-style devices. <em>Added in API level 9.</em></li>
508        </ul>
509        <p class="note"><strong>Note:</strong> Using a size qualifier does not imply that the
510resources are <em>only</em> for screens of that size. If you do not provide alternative
511resources with qualifiers that better match the current device configuration, the system may use
512whichever resources are the <a href="#BestMatch">best match</a>.</p>
513        <p class="caution"><strong>Caution:</strong> If all your resources use a size qualifier that
514is <em>larger</em> than the current screen, the system will <strong>not</strong> use them and your
515application will crash at runtime (for example, if all layout resources are tagged with the {@code
516xlarge} qualifier, but the device is a normal-size screen).</p>
517        <p><em>Added in API level 4.</em></p>
518        
519        <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
520Screens</a> for more information.</p>
521        <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
522which indicates whether the screen is small, normal,
523or large.</p>
524      </td>
525    </tr>
526    <tr id="ScreenAspectQualifier">
527      <td>Screen aspect</td>
528      <td>
529        <code>long</code><br/>
530        <code>notlong</code>
531      </td>
532      <td>
533        <ul class="nolist">
534          <li>{@code long}: Long screens, such as WQVGA, WVGA, FWVGA</li>
535          <li>{@code notlong}: Not long screens, such as QVGA, HVGA, and VGA</li>
536        </ul>
537        <p><em>Added in API level 4.</em></p>
538        <p>This is based purely on the aspect ratio of the screen (a "long" screen is wider). This
539is not related to the screen orientation.</p>
540        <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
541which indicates whether the screen is long.</p>
542      </td>
543    </tr>
544    <tr id="OrientationQualifier">
545      <td>Screen orientation</td>
546      <td>
547        <code>port</code><br/>
548        <code>land</code>  <!-- <br/>
549        <code>square</code>  -->
550      </td>
551      <td>
552        <ul class="nolist">
553          <li>{@code port}: Device is in portrait orientation (vertical)</li>
554          <li>{@code land}: Device is in landscape orientation (horizontal)</li>
555          <!-- Square mode is currently not used. -->
556        </ul>
557        <p>This can change during the life of your application if the user rotates the
558screen. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about
559how this affects your application during runtime.</p>
560        <p>Also see the {@link android.content.res.Configuration#orientation} configuration field,
561which indicates the current device orientation.</p>
562      </td>
563    </tr>
564    <tr id="UiModeQualifier">
565      <td>UI mode</td>
566      <td>
567        <code>car</code><br/>
568        <code>desk</code><br/>
569        <code>television<br/>
570        <code>appliance</code>
571      </td>
572      <td>
573        <ul class="nolist">
574          <li>{@code car}: Device is displaying in a car dock</li>
575          <li>{@code desk}: Device is displaying in a desk dock</li>
576          <li>{@code television}: Device is displaying on a television, providing
577          a "ten foot" experience where its UI is on a large screen that the
578          user is far away from, primarily oriented around DPAD or other
579          non-pointer interaction</li>
580          <li>{@code appliance}: Device is serving as an appliance, with
581          no display</li>
582        </ul>
583        <p><em>Added in API level 8, television added in API 13.</em></p>
584        <p>For information about how your app can respond when the device is inserted into or
585        removed from a dock, read <a 
586        href="{@docRoot}training/monitoring-device-state/docking-monitoring.html">Determining
587and Monitoring the Docking State and Type</a>.</p>
588        <p>This can change during the life of your application if the user places the device in a
589dock. You can enable or disable some of these modes using {@link
590android.app.UiModeManager}. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
591information about how this affects your application during runtime.</p>
592      </td>
593    </tr>
594    <tr id="NightQualifier">
595      <td>Night mode</td>
596      <td>
597        <code>night</code><br/>
598        <code>notnight</code>
599      </td>
600      <td>
601        <ul class="nolist">
602          <li>{@code night}: Night time</li>
603          <li>{@code notnight}: Day time</li>
604        </ul>
605        <p><em>Added in API level 8.</em></p>
606        <p>This can change during the life of your application if night mode is left in
607auto mode (default), in which case the mode changes based on the time of day.  You can enable
608or disable this mode using {@link android.app.UiModeManager}. See <a
609href="runtime-changes.html">Handling Runtime Changes</a> for information about how this affects your
610application during runtime.</p>
611      </td>
612    </tr>
613    <tr id="DensityQualifier">
614      <td>Screen pixel density (dpi)</td>
615      <td>
616        <code>ldpi</code><br/>
617        <code>mdpi</code><br/>
618        <code>hdpi</code><br/>
619        <code>xhdpi</code><br/>
620        <code>nodpi</code><br/>
621        <code>tvdpi</code>
622      </td>
623      <td>
624        <ul class="nolist">
625          <li>{@code ldpi}: Low-density screens; approximately 120dpi.</li>
626          <li>{@code mdpi}: Medium-density (on traditional HVGA) screens; approximately
627160dpi.</li>
628          <li>{@code hdpi}: High-density screens; approximately 240dpi.</li>
629          <li>{@code xhdpi}: Extra high-density screens; approximately 320dpi. <em>Added in API
630Level 8</em></li>
631          <li>{@code nodpi}: This can be used for bitmap resources that you do not want to be scaled
632to match the device density.</li>
633          <li>{@code tvdpi}: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is
634not considered a "primary" density group. It is mostly intended for televisions and most
635apps shouldn't need it&mdash;providing mdpi and hdpi resources is sufficient for most apps and
636the system will scale them as appropriate. This qualifier was introduced with API level 13.</li>
637        </ul>
638        <p>There is a 3:4:6:8 scaling ratio between the four primary densities (ignoring the
639tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi and 24x24 in xhdpi.</p>
640        <p>If you decide that your image resources don't look good enough on a television or
641other certain devices and want to try tvdpi resources, the scaling factor is 1.33*mdpi. For
642example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.</p>
643        <p class="note"><strong>Note:</strong> Using a density qualifier does not imply that the
644resources are <em>only</em> for screens of that density. If you do not provide alternative
645resources with qualifiers that better match the current device configuration, the system may use
646whichever resources are the <a href="#BestMatch">best match</a>.</p>
647        <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
648Screens</a> for more information about how to handle different screen densities and how Android
649might scale your bitmaps to fit the current density.</p>
650       </td>
651    </tr>
652    <tr id="TouchscreenQualifier">
653      <td>Touchscreen type</td>
654      <td>
655        <code>notouch</code><br/>
656        <code>finger</code>
657      </td>
658      <td>
659        <ul class="nolist">
660          <li>{@code notouch}: Device does not have a touchscreen.</li>
661          <li>{@code finger}: Device has a touchscreen that is intended to
662          be used through direction interaction of the user's finger.</li>
663        </ul>
664        <p>Also see the {@link android.content.res.Configuration#touchscreen} configuration field,
665which indicates the type of touchscreen on the device.</p>
666      </td>
667    </tr>
668    <tr id="KeyboardAvailQualifier">
669      <td>Keyboard availability</td>
670      <td>
671        <code>keysexposed</code><br/>
672        <code>keyshidden</code><br/>
673        <code>keyssoft</code>
674      </td>
675      <td>
676        <ul class="nolist">
677          <li>{@code keysexposed}: Device has a keyboard available. If the device has a
678software keyboard enabled (which is likely), this may be used even when the hardware keyboard is
679<em>not</em> exposed to the user, even if the device has no hardware keyboard. If no software
680keyboard is provided or it's disabled, then this is only used when a hardware keyboard is
681exposed.</li>
682          <li>{@code keyshidden}: Device has a hardware keyboard available but it is
683hidden <em>and</em> the device does <em>not</em> have a software keyboard enabled.</li>
684          <li>{@code keyssoft}: Device has a software keyboard enabled, whether it's
685visible or not.</li>
686        </ul>
687        <p>If you provide <code>keysexposed</code> resources, but not <code>keyssoft</code>
688resources, the system uses the <code>keysexposed</code> resources regardless of whether a
689keyboard is visible, as long as the system has a software keyboard enabled.</p>
690        <p>This can change during the life of your application if the user opens a hardware
691keyboard. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about how
692this affects your application during runtime.</p>
693        <p>Also see the configuration fields {@link
694android.content.res.Configuration#hardKeyboardHidden} and {@link
695android.content.res.Configuration#keyboardHidden}, which indicate the visibility of a hardware
696keyboard and and the visibility of any kind of keyboard (including software), respectively.</p>
697      </td>
698    </tr>
699    <tr id="ImeQualifier">
700      <td>Primary text input method</td>
701      <td>
702        <code>nokeys</code><br/>
703        <code>qwerty</code><br/>
704        <code>12key</code>
705      </td>
706      <td>
707        <ul class="nolist">
708          <li>{@code nokeys}: Device has no hardware keys for text input.</li>
709          <li>{@code qwerty}: Device has a hardware qwerty keyboard, whether it's visible to the
710user
711or not.</li>
712          <li>{@code 12key}: Device has a hardware 12-key keyboard, whether it's visible to the user
713or not.</li>
714        </ul>
715        <p>Also see the {@link android.content.res.Configuration#keyboard} configuration field,
716which indicates the primary text input method available.</p>
717      </td>
718    </tr>
719    <tr id="NavAvailQualifier">
720      <td>Navigation key availability</td>
721      <td>
722        <code>navexposed</code><br/>
723        <code>navhidden</code>
724      </td>
725      <td>
726        <ul class="nolist">
727          <li>{@code navexposed}: Navigation keys are available to the user.</li>
728          <li>{@code navhidden}: Navigation keys are not available (such as behind a closed
729lid).</li>
730        </ul>
731        <p>This can change during the life of your application if the user reveals the navigation
732keys. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
733information about how this affects your application during runtime.</p>
734        <p>Also see the {@link android.content.res.Configuration#navigationHidden} configuration
735field, which indicates whether navigation keys are hidden.</p>
736      </td>
737    </tr>
738    <tr id="NavigationQualifier">
739      <td>Primary non-touch navigation method</td>
740      <td>
741        <code>nonav</code><br/>
742        <code>dpad</code><br/>
743        <code>trackball</code><br/>
744        <code>wheel</code>
745      </td>
746      <td>
747        <ul class="nolist">
748          <li>{@code nonav}: Device has no navigation facility other than using the
749touchscreen.</li>
750          <li>{@code dpad}: Device has a directional-pad (d-pad) for navigation.</li>
751          <li>{@code trackball}: Device has a trackball for navigation.</li>
752          <li>{@code wheel}: Device has a directional wheel(s) for navigation (uncommon).</li>
753        </ul>
754        <p>Also see the {@link android.content.res.Configuration#navigation} configuration field,
755which indicates the type of navigation method available.</p>
756      </td>
757    </tr>
758<!-- DEPRECATED
759    <tr>
760      <td>Screen dimensions</td>
761      <td>Examples:<br/>
762        <code>320x240</code><br/>
763        <code>640x480</code><br/>
764        etc.
765      </td>
766      <td>
767        <p>The larger dimension must be specified first. <strong>This configuration is deprecated
768and should not be used</strong>. Instead use "screen size," "wider/taller screens," and "screen
769orientation" described above.</p>
770      </td>
771    </tr>
772-->
773    <tr id="VersionQualifier">
774      <td>Platform Version (API level)</td>
775      <td>Examples:<br/>
776        <code>v3</code><br/>
777        <code>v4</code><br/>
778        <code>v7</code><br/>
779        etc.</td>
780      <td>
781        <p>The API level supported by the device. For example, <code>v1</code> for API level
7821 (devices with Android 1.0 or higher) and <code>v4</code> for API level 4 (devices with Android
7831.6 or higher). See the <a
784href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">Android API levels</a> document for more information
785about these values.</p>
786        <p class="caution"><strong>Caution:</strong> Android 1.5 and 1.6 only match resources
787with this qualifier when it exactly matches the platform version. See the section below about <a
788href="#KnownIssues">Known Issues</a> for more information.</p>
789      </td>
790    </tr>
791</table>
792
793
794<p class="note"><strong>Note:</strong> Some configuration qualifiers have been added since Android
7951.0, so not all versions of Android support all the qualifiers. Using a new qualifier implicitly
796adds the platform version qualifier so that older devices are sure to ignore it. For example, using
797a <code>w600dp</code> qualifier will automatically include the <code>v13</code> qualifier, because
798the available-width qualifier was new in API level 13. To avoid any issues, always include a set of
799default resources (a set of resources with <em>no qualifiers</em>). For more information, see the
800section about <a href="#Compatibility">Providing the Best Device Compatibility with
801Resources</a>.</p>
802
803
804
805<h3 id="QualifierRules">Qualifier name rules</h3>
806
807<p>Here are some rules about using configuration qualifier names:</p>
808
809<ul>
810    <li>You can specify multiple qualifiers for a single set of resources, separated by dashes. For
811example, <code>drawable-en-rUS-land</code> applies to US-English devices in landscape
812orientation.</li>
813    <li>The qualifiers must be in the order listed in <a href="#table2">table 2</a>. For
814example:
815      <ul>
816        <li>Wrong: <code>drawable-hdpi-port/</code></li>
817        <li>Correct: <code>drawable-port-hdpi/</code></li>
818      </ul>
819    </li>
820    <li>Alternative resource directories cannot be nested. For example, you cannot have
821<code>res/drawable/drawable-en/</code>.</li>
822    <li>Values are case-insensitive.  The resource compiler converts directory names
823    to lower case before processing to avoid problems on case-insensitive
824    file systems. Any capitalization in the names is only to benefit readability.</li>
825    <li>Only one value for each qualifier type is supported. For example, if you want to use
826the same drawable files for Spain and France, you <em>cannot</em> have a directory named
827<code>drawable-rES-rFR/</code>. Instead you need two resource directories, such as
828<code>drawable-rES/</code> and <code>drawable-rFR/</code>, which contain the appropriate files.
829However, you are not required to actually duplicate the same files in both locations. Instead, you
830can create an alias to a resource. See <a href="#AliasResources">Creating
831alias resources</a> below.</li>
832</ul>
833
834<p>After you save alternative resources into directories named with
835these qualifiers, Android automatically applies the resources in your application based on the
836current device configuration. Each time a resource is requested, Android checks for alternative
837resource directories that contain the requested resource file, then <a href="#BestMatch">finds the
838best-matching resource</a> (discussed below). If there are no alternative resources that match
839a particular device configuration, then Android uses the corresponding default resources (the
840set of resources for a particular resource type that does not include a configuration
841qualifier).</p>
842
843
844
845<h3 id="AliasResources">Creating alias resources</h3>
846
847<p>When you have a resource that you'd like to use for more than one device
848configuration (but do not want to provide as a default resource), you do not need to put the same
849resource in more than one alternative resource directory. Instead, you can (in some cases) create an
850alternative
851resource that acts as an alias for a resource saved in your default resource directory.</p>
852
853<p class="note"><strong>Note:</strong> Not all resources offer a mechanism by which you can
854create an alias to another resource. In particular, animation, menu, raw, and other unspecified
855resources in the {@code xml/} directory do not offer this feature.</p>
856
857<p>For example, imagine you have an application icon, {@code icon.png}, and need unique version of
858it for different locales. However, two locales, English-Canadian and French-Canadian, need to
859use the same version. You might assume that you need to copy the same image
860into the resource directory for both English-Canadian and French-Canadian, but it's
861not true. Instead, you can save the image that's used for both as {@code icon_ca.png} (any
862name other than {@code icon.png}) and put
863it in the default {@code res/drawable/} directory. Then create an {@code icon.xml} file in {@code
864res/drawable-en-rCA/} and {@code res/drawable-fr-rCA/} that refers to the {@code icon_ca.png}
865resource using the {@code &lt;bitmap&gt;} element. This allows you to store just one version of the
866PNG file and two small XML files that point to it. (An example XML file is shown below.)</p>
867
868
869<h4>Drawable</h4>
870
871<p>To create an alias to an existing drawable, use the {@code &lt;bitmap&gt;} element.
872For example:</p>
873
874<pre>
875&lt;?xml version="1.0" encoding="utf-8"?>
876&lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android"
877    android:src="@drawable/icon_ca" />
878</pre>
879
880<p>If you save this file as {@code icon.xml} (in an alternative resource directory, such as
881{@code res/drawable-en-rCA/}), it is compiled into a resource that you
882can reference as {@code R.drawable.icon}, but is actually an alias for the {@code
883R.drawable.icon_ca} resource (which is saved in {@code res/drawable/}).</p>
884
885
886<h4>Layout</h4>
887
888<p>To create an alias to an existing layout, use the {@code &lt;include&gt;}
889element, wrapped in a {@code &lt;merge&gt;}. For example:</p>
890
891<pre>
892&lt;?xml version="1.0" encoding="utf-8"?>
893&lt;merge>
894    &lt;include layout="@layout/main_ltr"/>
895&lt;/merge>
896</pre>
897
898<p>If you save this file as {@code main.xml}, it is compiled into a resource you can reference
899as {@code R.layout.main}, but is actually an alias for the {@code R.layout.main_ltr}
900resource.</p>
901
902
903<h4>Strings and other simple values</h4>
904
905<p>To create an alias to an existing string, simply use the resource ID of the desired
906string as the value for the new string. For example:</p>
907
908<pre>
909&lt;?xml version="1.0" encoding="utf-8"?>
910&lt;resources>
911    &lt;string name="hello">Hello&lt;/string>
912    &lt;string name="hi">@string/hello&lt;/string>
913&lt;/resources>
914</pre>
915
916<p>The {@code R.string.hi} resource is now an alias for the {@code R.string.hello}.</p>
917
918<p> <a href="{@docRoot}guide/topics/resources/more-resources.html">Other simple values</a> work the
919same way. For example, a color:</p>
920
921<pre>
922&lt;?xml version="1.0" encoding="utf-8"?>
923&lt;resources>
924    &lt;color name="yellow">#f00&lt;/color>
925    &lt;color name="highlight">@color/red&lt;/color>
926&lt;/resources>
927</pre>
928
929
930
931
932<h2 id="Compatibility">Providing the Best Device Compatibility with Resources</h2>
933
934<p>In order for your application to support multiple device configurations, it's very important that
935you always provide default resources for each type of resource that your application uses.</p>
936
937<p>For example, if your application supports several languages, always include a {@code
938values/} directory (in which your strings are saved) <em>without</em> a <a
939href="#LocaleQualifier">language and region qualifier</a>. If you instead put all your string files
940in directories that have a language and region qualifier, then your application will crash when run
941on a device set to a language that your strings do not support. But, as long as you provide default
942{@code values/} resources, then your application will run properly (even if the user doesn't
943understand that language&mdash;it's better than crashing).</p>
944
945<p>Likewise, if you provide different layout resources based on the screen orientation, you should
946pick one orientation as your default. For example, instead of providing layout resources in {@code
947layout-land/} for landscape and {@code layout-port/} for portrait, leave one as the default, such as
948{@code layout/} for landscape and {@code layout-port/} for portrait.</p>
949
950<p>Providing default resources is important not only because your application might run on a
951configuration you had not anticipated, but also because new versions of Android sometimes add
952configuration qualifiers that older versions do not support. If you use a new resource qualifier,
953but maintain code compatibility with older versions of Android, then when an older version of
954Android runs your application, it will crash if you do not provide default resources, because it
955cannot use the resources named with the new qualifier. For example, if your <a
956href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
957minSdkVersion}</a> is set to 4, and you qualify all of your drawable resources using <a
958href="#NightQualifier">night mode</a> ({@code night} or {@code notnight}, which were added in API
959Level 8), then an API level 4 device cannot access your drawable resources and will crash. In this
960case, you probably want {@code notnight} to be your default resources, so you should exclude that
961qualifier so your drawable resources are in either {@code drawable/} or {@code drawable-night/}.</p>
962
963<p>So, in order to provide the best device compatibility, always provide default
964resources for the resources your application needs to perform properly. Then create alternative
965resources for specific device configurations using the configuration qualifiers.</p>
966
967<p>There is one exception to this rule: If your application's <a
968href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> is 4 or
969greater, you <em>do not</em> need default drawable resources when you provide alternative drawable
970resources with the <a href="#DensityQualifier">screen density</a> qualifier. Even without default
971drawable resources, Android can find the best match among the alternative screen densities and scale
972the bitmaps as necessary. However, for the best experience on all types of devices, you should
973provide alternative drawables for all three types of density. If your <a
974href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> is
975<em>less than</em> 4 (Android 1.5 or lower), be aware that the screen size, density, and aspect
976qualifiers are not supported on Android 1.5 or lower, so you might need to perform additional
977compatibility for these versions.</p>
978
979
980<h3 id="ScreenCompatibility">Providing screen resource compatibility for Android 1.5</h3>
981
982<p>Android 1.5 (and lower) does not support the following configuration qualifers:</p>
983<dl>
984  <dt><a href="#DensityQualifier">Density</a></dt>
985    <dd>{@code ldpi}, {@code mdpi}, {@code ldpi}, and {@code nodpi}</dd>
986  <dt><a href="#ScreenSizeQualifier">Screen size</a></dt>
987    <dd>{@code small}, {@code normal}, and {@code large}</dd>
988  <dt><a href="#ScreenAspectQualifier">Screen aspect</a></dt>
989    <dd>{@code long} and {@code notlong}</dd>
990</dl>
991
992<p>These configuration qualifiers were introduced in Android 1.6, so Android 1.5 (API level 3) and
993lower does not support them. If you use these configuration qualifiers and do not provide
994corresponding default resources, then an Android 1.5 device might use any one of the resource
995directories named with the above screen configuration qualifiers, because it ignores these
996qualifiers and uses whichever otherwise-matching drawable resource it finds first.</p>
997
998<p>For example, if your application supports Android 1.5 and includes drawable resources for
999each density type ({@code drawable-ldpi/}, {@code drawable-mdpi/}, and {@code drawable-ldpi/}),
1000and does <em>not</em> include default drawable resources ({@code drawable/}), then
1001an Android 1.5 will use drawables from any one of the alternative resource directories, which
1002can result in a user interface that's less than ideal.<p>
1003
1004<p>So, to provide compatibility with Android 1.5 (and lower) when using the screen configuration
1005qualifiers:</p>
1006<ol>
1007  <li>Provide default resources that are for medium-density, normal, and notlong screens.
1008
1009    <p>Because all Android 1.5 devices have medium-density, normal, not-long screens, you can
1010place these kinds of resources in the corresponding default resource directory. For example, put all
1011medium density drawable resources in {@code drawable/} (instead of {@code drawable-mdpi/}),
1012put {@code normal} size resources in the corresponding default resource directory, and {@code
1013notlong} resources in the corresponding default resource directory.</p>
1014  </li>
1015
1016  <li>Ensure that your <a href="{@docRoot}tools/sdk/tools-notes.html">SDK Tools</a> version
1017is r6 or greater.
1018
1019    <p>You need SDK Tools, Revision 6 (or greater), because it includes a new packaging tool that
1020automatically applies an appropriate <a href="#VersionQualifier">version qualifier</a> to any
1021resource directory named with a qualifier that does not exist in Android 1.0. For example, because
1022the density qualifier was introduced in Android 1.6 (API level 4), when the packaging tool
1023encounters a resource directory using the density qualifier, it adds {@code v4} to the directory
1024name to ensure that older versions do not use those resources (only API level 4 and higher support
1025that qualifier). Thus, by putting your medium-density resources in a directory <em>without</em> the
1026{@code mdpi} qualifier, they are still accessible by Android 1.5, and any device that supports the
1027density qualifer and has a medium-density screen also uses the default resources (which are mdpi)
1028because they are the best match for the device (instead of using the {@code ldpi} or {@code hdpi}
1029resources).</p>
1030</li>
1031</ol>
1032
1033<p class="note"><strong>Note:</strong> Later versions of Android, such as API level 8,
1034introduce other configuration qualifiers that older version do not support. To provide the best
1035compatibility, you should always include a set of default resources for each type of resource
1036that your application uses, as discussed above to provide the best device compatibility.</p>
1037
1038
1039
1040<h2 id="BestMatch">How Android Finds the Best-matching Resource</h2>
1041
1042<p>When you request a resource for which you provide alternatives, Android selects which
1043alternative resource to use at runtime, depending on the current device configuration. To
1044demonstrate how Android selects an alternative resource, assume the following drawable directories
1045each contain different versions of the same images:</p>
1046
1047<pre class="classic no-pretty-print">
1048drawable/
1049drawable-en/
1050drawable-fr-rCA/
1051drawable-en-port/
1052drawable-en-notouch-12key/
1053drawable-port-ldpi/
1054drawable-port-notouch-12key/
1055</pre>
1056
1057<p>And assume the following is the device configuration:</p>
1058
1059<p style="margin-left:1em;">
1060Locale = <code>en-GB</code> <br/>
1061Screen orientation = <code>port</code> <br/>
1062Screen pixel density = <code>hdpi</code> <br/>
1063Touchscreen type = <code>notouch</code> <br/>
1064Primary text input method = <code>12key</code>
1065</p>
1066
1067<p>By comparing the device configuration to the available alternative resources, Android selects
1068drawables from {@code drawable-en-port}.</p>
1069
1070<p>The system arrives at its decision for which resources to use with the following
1071logic:</p>
1072
1073
1074<div class="figure" style="width:371px">
1075<img src="{@docRoot}images/resources/res-selection-flowchart.png" alt="" height="471" />
1076<p class="img-caption"><strong>Figure 2.</strong> Flowchart of how Android finds the
1077best-matching resource.</p>
1078</div>
1079
1080
1081<ol>
1082  <li>Eliminate resource files that contradict the device configuration.
1083    <p>The <code>drawable-fr-rCA/</code> directory is eliminated, because it
1084contradicts the <code>en-GB</code> locale.</p>
1085<pre class="classic no-pretty-print">
1086drawable/
1087drawable-en/
1088<strike>drawable-fr-rCA/</strike>
1089drawable-en-port/
1090drawable-en-notouch-12key/
1091drawable-port-ldpi/
1092drawable-port-notouch-12key/
1093</pre>
1094<p class="note"><strong>Exception:</strong> Screen pixel density is the one qualifier that is not
1095eliminated due to a contradiction. Even though the screen density of the device is hdpi,
1096<code>drawable-port-ldpi/</code> is not eliminated because every screen density is
1097considered to be a match at this point. More information is available in the <a
1098href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1099Screens</a> document.</p></li>
1100
1101  <li>Pick the (next) highest-precedence qualifier in the list (<a href="#table2">table 2</a>).
1102(Start with MCC, then move down.) </li>
1103  <li>Do any of the resource directories include this qualifier?  </li>
1104    <ul>
1105      <li>If No, return to step 2 and look at the next qualifier. (In the example,
1106  the answer is &quot;no&quot; until the language qualifier is reached.)</li>
1107      <li>If Yes, continue to step 4.</li>
1108    </ul>
1109  </li>
1110
1111  <li>Eliminate resource directories that do not include this qualifier. In the example, the system
1112eliminates all the directories that do not include a language qualifier:</li>
1113<pre class="classic no-pretty-print">
1114<strike>drawable/</strike>
1115drawable-en/
1116drawable-en-port/
1117drawable-en-notouch-12key/
1118<strike>drawable-port-ldpi/</strike>
1119<strike>drawable-port-notouch-12key/</strike>
1120</pre>
1121<p class="note"><strong>Exception:</strong> If the qualifier in question is screen pixel density,
1122Android selects the option that most closely matches the device screen density.
1123In general, Android prefers scaling down a larger original image to scaling up a smaller
1124original image. See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1125Screens</a>.</p>
1126  </li>
1127
1128  <li>Go back and repeat steps 2, 3, and 4 until only one directory remains. In the example, screen
1129orientation is the next qualifier for which there are any matches.
1130So, resources that do not specify a screen orientation are eliminated:
1131<pre class="classic no-pretty-print">
1132<strike>drawable-en/</strike>
1133drawable-en-port/
1134<strike>drawable-en-notouch-12key/</strike>
1135</pre>
1136<p>The remaining directory is {@code drawable-en-port}.</p>
1137  </li>
1138</ol>
1139
1140<p>Though this procedure is executed for each resource requested, the system further optimizes
1141some aspects. One such optimization is that once the device configuration is known, it might
1142eliminate alternative resources that can never match. For example, if the configuration
1143language is English ("en"), then any resource directory that has a language qualifier set to
1144something other than English is never included in the pool of resources checked (though a
1145resource directory <em>without</em> the language qualifier is still included).</p>
1146
1147<p>When selecting resources based on the screen size qualifiers, the system will use resources
1148designed for a screen smaller than the current screen if there are no resources that better match
1149(for example, a large-size screen will use normal-size screen resources if necessary). However, if
1150the only available resources are <em>larger</em> than the current screen, the system will
1151<strong>not</strong> use them and your application will crash if no other resources match the device
1152configuration (for example, if all layout resources are tagged with the {@code xlarge} qualifier,
1153but the device is a normal-size screen).</p>
1154
1155<p class="note"><strong>Note:</strong> The <em>precedence</em> of the qualifier (in <a
1156href="#table2">table 2</a>) is more important
1157than the number of qualifiers that exactly match the device. For example, in step 4 above, the last
1158choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen
1159type, and input method), while <code>drawable-en</code> has only one parameter that matches
1160(language). However, language has a higher precedence than these other qualifiers, so
1161<code>drawable-port-notouch-12key</code> is out.</p>
1162
1163<p>To learn more about how to use resources in your application, continue to <a
1164href="accessing-resources.html">Accessing Resources</a>.</p>
1165
1166
1167
1168
1169<h2 id="KnownIssues">Known Issues</h2>
1170
1171<h3>Android 1.5 and 1.6: Version qualifier performs exact match, instead of best match</h3>
1172
1173<p>The correct behavior is for the system to match resources marked with a <a
1174href="#VersionQualifier">version qualifier</a> equal
1175to or less than the platform version on the device, but on Android 1.5 and 1.6, (API level 3 and 4),
1176there is a bug that causes the system to match resources marked with the version qualifier
1177only when it exactly matches the version on the device.</p>
1178
1179<p><b>The workaround:</b> To provide version-specific resources, abide by this behavior. However,
1180because this bug is fixed in versions of Android available after 1.6, if
1181you need to differentiate resources between Android 1.5, 1.6, and later versions, then you only need
1182to apply the version qualifier to the 1.6 resources and one to match all later versions. Thus, this
1183is effectively a non-issue.</p>
1184
1185<p>For example, if you want drawable resources that are different on each Android 1.5, 1.6,
1186and 2.0.1 (and later), create three drawable directories: {@code drawable/} (for 1.5 and lower),
1187{@code drawable-v4} (for 1.6), and {@code drawable-v6} (for 2.0.1 and later&mdash;version 2.0, v5,
1188is no longer available).</p>
1189
1190
1191