1f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainpage.title=Providing Resources
2f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainparent.title=Application Resources
3f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainparent.link=index.html
4f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main@jd:body
5f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
6f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<div id="qv-wrapper">
7f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<div id="qv">
8f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <h2>Quickview</h2>
9f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <ul>
10c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <li>Different types of resources belong in different subdirectories of {@code res/}</li>
11f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li>Alternative resources provide configuration-specific resource files</li>
12821ca51857f4d21b231cd9ead786227b771fe759Scott Main    <li>Always include default resources so your app does not depend on specific
13821ca51857f4d21b231cd9ead786227b771fe759Scott Maindevice configurations</li>
14f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </ul>
15f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <h2>In this document</h2>
16f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <ol>
17c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <li><a href="#ResourceTypes">Grouping Resource Types</a></li>
18f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li><a href="#AlternativeResources">Providing Alternative Resources</a>
19f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <ol>
20c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li><a href="#QualifierRules">Qualifier name rules</a></li>
21f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li><a href="#AliasResources">Creating alias resources</a></li>
22f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </ol>
23f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </li>
24c89312091e291c3e0cdb3cb7df3f76250fce7d22Scott Main    <li><a href="#Compatibility">Providing the Best Device Compatibility with Resources</a></li>
25f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li><a href="#BestMatch">How Android Finds the Best-matching Resource</a></li>
26f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </ol>
27f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
28f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <h2>See also</h2>
29f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <ol>
30f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li><a href="accessing-resources.html">Accessing Resources</a></li>
31f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li><a href="available-resources.html">Resource Types</a></li>
32c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <li><a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
33c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainScreens</a></li>
34f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </ol>
35f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</div>
36f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</div>
37f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
38c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>You should always externalize application resources such as images and strings from your
39821ca51857f4d21b231cd9ead786227b771fe759Scott Maincode, so that you can maintain them independently. You should also provide alternative resources for
40821ca51857f4d21b231cd9ead786227b771fe759Scott Mainspecific device configurations, by grouping them in specially-named resource directories. At
4150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainruntime, Android uses the appropriate resource based on the current configuration. For
42821ca51857f4d21b231cd9ead786227b771fe759Scott Mainexample, you might want to provide a different UI layout depending on the screen size or different
43821ca51857f4d21b231cd9ead786227b771fe759Scott Mainstrings depending on the language setting.</p>
44f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
457ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>Once you externalize your application resources, you can access them
46c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainusing resource IDs that are generated in your project's {@code R} class. How to use
47c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresources in your application is discussed in <a href="accessing-resources.html">Accessing
487ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott MainResources</a>. This document shows you how to group your resources in your Android project and
497ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainprovide alternative resources for specific device configurations.</p>
50f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
51c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
52c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<h2 id="ResourceTypes">Grouping Resource Types</h2>
53c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
54c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>You should place each type of resource in a specific subdirectory of your project's
55c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main{@code res/} directory. For example, here's the file hierarchy for a simple project:</p>
56c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
57c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
58f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainMyProject/
59f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    src/  <span style="color:black">
60f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        MyActivity.java  </span>
61f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    res/
62f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        drawable/  <span style="color:black">
63f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main            icon.png  </span>
64f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        layout/  <span style="color:black">
65c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main            main.xml
66c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main            info.xml</span>
67f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        values/  <span style="color:black">
68f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main            strings.xml  </span>
69f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
70f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
717ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>As you can see in this example, the {@code res/} directory contains all the resources (in
727ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainsubdirectories): an image resource, two layout resources, and a string resource file. The resource
737ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maindirectory names are important and are described in table 1.</p>
74f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
75c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p class="table-caption" id="table1"><strong>Table 1.</strong> Resource directories
76c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainsupported inside project {@code res/} directory.</p>
77f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
78f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<table>
79f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
80f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <th scope="col">Directory</th>
81c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <th scope="col">Resource Type</th>
82f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
83f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
84f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
8599960b73e986409f61c5b5d05aa04dea3105a663Scott Main    <td><code>animator/</code></td>
8650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    <td>XML files that define <a href="{@docRoot}guide/topics/graphics/prop-animation.html">property
8799960b73e986409f61c5b5d05aa04dea3105a663Scott Mainanimations</a>.</td>
8899960b73e986409f61c5b5d05aa04dea3105a663Scott Main  </tr>
8999960b73e986409f61c5b5d05aa04dea3105a663Scott Main
9099960b73e986409f61c5b5d05aa04dea3105a663Scott Main  <tr>
91f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>anim/</code></td>
9299960b73e986409f61c5b5d05aa04dea3105a663Scott Main    <td>XML files that define <a
9399960b73e986409f61c5b5d05aa04dea3105a663Scott Mainhref="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">tween
9499960b73e986409f61c5b5d05aa04dea3105a663Scott Mainanimations</a>. (Property animations can also be saved in this directory, but
9599960b73e986409f61c5b5d05aa04dea3105a663Scott Mainthe {@code animator/} directory is preferred for property animations to distinguish between the two
9699960b73e986409f61c5b5d05aa04dea3105a663Scott Maintypes.)</td>
97f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
98f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
99f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
100f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>color/</code></td>
101f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td>XML files that define a state list of colors. See <a href="color-list-resource.html">Color
102c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainState List Resource</a></td>
103f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
104f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
105f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
106f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>drawable/</code></td>
107f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><p>Bitmap files ({@code .png}, {@code .9.png}, {@code .jpg}, {@code .gif}) or XML files that
108c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainare compiled into the following drawable resource subtypes:</p>
109f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <ul>
110f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Bitmap files</li>
111f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Nine-Patches (re-sizable bitmaps)</li>
112f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>State lists</li>
113f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Shapes</li>
114f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Animation drawables</li>
1157ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main        <li>Other drawables</li>
116f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </ul>
117f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <p>See <a href="drawable-resource.html">Drawable Resources</a>.</p>
118f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </td>
119f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
120f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
121f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
122f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>layout/</code></td>
123f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td>XML files that define a user interface layout.
124f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        See <a href="layout-resource.html">Layout Resource</a>.</td>
125f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
126f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
127f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
128f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>menu/</code></td>
129f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td>XML files that define application menus, such as an Options Menu, Context Menu, or Sub
130f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainMenu. See <a href="menu-resource.html">Menu Resource</a>.</td>
131f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
132f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
133f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
134f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>raw/</code></td>
1357025d8e4b96f14a92f9bb20902732f43d1c93e7bDianne Hackborn    <td><p>Arbitrary files to save in their raw form. To open these resources with a raw
1367025d8e4b96f14a92f9bb20902732f43d1c93e7bDianne Hackborn{@link java.io.InputStream}, call {@link android.content.res.Resources#openRawResource(int)
137f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainResources.openRawResource()} with the resource ID, which is {@code R.raw.<em>filename</em>}.</p>
138c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <p>However, if you need access to original file names and file hierarchy, you might consider
139c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainsaving some resources in the {@code
140c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainassets/} directory (instead of {@code res/raw/}). Files in {@code assets/} are not given a
141c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresource ID, so you can read them only using {@link android.content.res.AssetManager}.</p></td>
142f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
143f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
144f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
145f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>values/</code></td>
146f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><p>XML files that contain simple values, such as strings, integers, and colors.</p>
147c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <p>Whereas XML resource files in other {@code res/} subdirectories define a single resource
148c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainbased on the XML filename, files in the {@code values/} directory describe multiple resources.
149c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainFor a file in this directory, each child of the {@code &lt;resources&gt;} element defines a single
150c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresource. For example, a {@code &lt;string&gt;} element creates an
151c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main{@code R.string} resource and a  {@code &lt;color&gt;} element creates an {@code R.color}
152f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainresource.</p>
153c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <p>Because each resource is defined with its own XML element, you can name the file
154c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhatever you want and place different resource types in one file. However, for clarity, you might
155c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwant to place unique resource types in different files. For example, here are some filename
156c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainconventions for resources you can create in this directory:</p>
157f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <ul>
158c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li>arrays.xml for resource arrays (<a
159f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="more-resources.html#TypedArray">typed arrays</a>).</li>
160c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li>colors.xml for <a
161f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="more-resources.html#Color">color values</a></li>
162c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li>dimens.xml for <a
163f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="more-resources.html#Dimension">dimension values</a>.</li>
164c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li>strings.xml for <a href="string-resource.html">string
165f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainvalues</a>.</li>
166c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <li>styles.xml for <a href="style-resource.html">styles</a>.</li>
167f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </ul>
168f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <p>See <a href="string-resource.html">String Resources</a>,
169f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <a href="style-resource.html">Style Resource</a>, and
170f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <a href="more-resources.html">More Resource Types</a>.</p>
171f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </td>
172f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
173f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
174f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <tr>
175f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <td><code>xml/</code></td>
176c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <td>Arbitrary XML files that can be read at runtime by calling {@link
177f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainandroid.content.res.Resources#getXml(int) Resources.getXML()}. Various XML configuration files
178c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainmust be saved here, such as a <a
179f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="{@docRoot}guide/topics/search/searchable-config.html">searchable configuration</a>.
180f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<!-- or preferences configuration. --></td>
181f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </tr>
182f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</table>
183f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1847ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p class="caution"><strong>Caution:</strong> Never save resource files directly inside the
1857ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main{@code res/} directory&mdash;it will cause a compiler error.</p>
186c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
187f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>For more information about certain types of resources, see the <a
188f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="available-resources.html">Resource Types</a> documentation.</p>
189f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1907ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>The resources that you save in the subdirectories defined in table 1 are your "default"
1917ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainresources. That is, these resources define the default design and content for your application.
1927ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott MainHowever, different types of Android-powered devices might call for different types of resources.
1937ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott MainFor example, if a device has a larger than normal screen, then you should provide
1947ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maindifferent layout resources that take advantage of the extra screen space. Or, if a device has a
1957ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maindifferent language setting, then you should provide different string resources that translate the
1967ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maintext in your user interface. To provide these different resources for different device
197821ca51857f4d21b231cd9ead786227b771fe759Scott Mainconfigurations, you need to provide alternative resources, in addition to your default
1987ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainresources.</p>
199f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
200f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
201f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h2 id="AlternativeResources">Providing Alternative Resources</h2>
202f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
203f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
204e63163a3349a542fcdefbf793a87696b6cbea3d8Scott Main<div class="figure" style="width:429px">
205e63163a3349a542fcdefbf793a87696b6cbea3d8Scott Main<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="167" alt="" />
206f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p class="img-caption">
207e63163a3349a542fcdefbf793a87696b6cbea3d8Scott Main<strong>Figure 1.</strong> Two different devices, each using different layout resources.</p>
208f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</div>
209f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
210f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>Almost every application should provide alternative resources to support specific device
211c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainconfigurations. For instance, you should include alternative drawable resources for different
212c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainscreen densities and alternative string resources for different languages. At runtime, Android
2137ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maindetects the current device configuration and loads the appropriate
2147ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainresources for your application.</p>
215f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
216c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>To specify configuration-specific alternatives for a set of resources:</p>
217f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<ol>
218f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <li>Create a new directory in {@code res/} named in the form {@code
219f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<em>&lt;resources_name&gt;</em>-<em>&lt;config_qualifier&gt;</em>}.
220f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <ul>
221f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <li><em>{@code &lt;resources_name&gt;}</em> is the directory name of the corresponding default
2227ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainresources (defined in table 1).</li>
223821ca51857f4d21b231cd9ead786227b771fe759Scott Main      <li><em>{@code &lt;qualifier&gt;}</em> is a name that specifies an individual configuration
2247ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainfor which these resources are to be used (defined in table 2).</li>
225f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </ul>
226821ca51857f4d21b231cd9ead786227b771fe759Scott Main    <p>You can append more than one <em>{@code &lt;qualifier&gt;}</em>. Separate each
227f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainone with a dash.</p>
228be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main    <p class="caution"><strong>Caution:</strong> When appending multiple qualifiers, you must
229be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainplace them in the same order in which they are listed in table 2. If the qualifiers are ordered
230be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainwrong, the resources are ignored.</p>
231f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </li>
2327ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main  <li>Save the respective alternative resources in this new directory. The resource files must be
2337ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainnamed exactly the same as the default resource files.</li>
234f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</ol>
235f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
236f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>For example, here are some default and alternative resources:</p>
237f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
238c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
239f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainres/
240f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    drawable/   <span style="color:black">
241f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        icon.png
242f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        background.png    </span>
243f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    drawable-hdpi/  <span style="color:black">
244f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        icon.png
245f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        background.png  </span>
246f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
247f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
248c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>The {@code hdpi} qualifier indicates that the resources in that directory are for devices with a
2497ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainhigh-density screen. The images in each of these drawable directories are sized for a specific
2507ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainscreen density, but the filenames are exactly
251c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainthe same. This way, the resource ID that you use to reference the {@code icon.png} or {@code
252c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainbackground.png} image is always the same, but Android selects the
2537ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainversion of each resource that best matches the current device, by comparing the device
254be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainconfiguration information with the qualifiers in the resource directory name.</p>
255f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
256f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>Android supports several configuration qualifiers and you can
257c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainadd multiple qualifiers to one directory name, by separating each qualifier with a dash. Table 2
258c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainlists the valid configuration qualifiers, in order of precedence&mdash;if you use multiple
259be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainqualifiers for a resource directory, you must add them to the directory name in the order they
2607ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainare listed in the table.</p>
261f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
262f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
263821ca51857f4d21b231cd9ead786227b771fe759Scott Main<p class="table-caption" id="table2"><strong>Table 2.</strong> Configuration qualifier
264f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainnames.</p>
265c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<table>
266f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <tr>
267c7eb47fad4fe39bd85c6205e38426c1867b9ed92Scott Main        <th>Configuration</th>
268c7eb47fad4fe39bd85c6205e38426c1867b9ed92Scott Main        <th>Qualifier Values</th>
269f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <th>Description</th>
270f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
2717ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="MccQualifier">
272f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>MCC and MNC</td>
273f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Examples:<br/>
274f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>mcc310</code><br/>
275f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code><nobr>mcc310-mnc004</nobr></code><br/>
276f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>mcc208-mnc00</code><br/>
277f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        etc.
278f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
279f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
280c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>The mobile country code (MCC), optionally followed by mobile network code (MNC)
281c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        from the SIM card in the device. For example, <code>mcc310</code> is U.S. on any carrier,
282f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>mcc310-mnc004</code> is U.S. on Verizon, and <code>mcc208-mnc00</code> is France on
283f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        Orange.</p>
2848edad6f16fc1d60a163e0f63153ff4f8a95e6c0eScott Main        <p>If the device uses a radio connection (GSM phone), the MCC and MNC values come
2858edad6f16fc1d60a163e0f63153ff4f8a95e6c0eScott Main        from the SIM card.</p>
286c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>You can also use the MCC alone (for example, to include country-specific legal
287c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresources in your application). If you need to specify based on the language only, then use the
288c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<em>language and region</em> qualifier instead (discussed next). If you decide to use the MCC and
289c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainMNC qualifier, you should do so with care and test that it works as expected.</p>
290c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the configuration fields {@link
291c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainandroid.content.res.Configuration#mcc}, and {@link
292c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainandroid.content.res.Configuration#mnc}, which indicate the current mobile country code
293c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainand mobile network code, respectively.</p>
294c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      </td>
295f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
2967ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="LocaleQualifier">
297f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Language and region</td>
298f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Examples:<br/>
299f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>en</code><br/>
300f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>fr</code><br/>
301f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>en-rUS</code><br/>
302f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>fr-rFR</code><br/>
303f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>fr-rCA</code><br/>
304f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        etc.
305f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
306c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <td><p>The language is defined by a two-letter <a
307f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
308f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main              639-1</a> language code, optionally followed by a two letter
309f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main              <a
310f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
311c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main              3166-1-alpha-2</a> region code (preceded by lowercase &quot;{@code r}&quot;).
312f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        </p><p>
313f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        The codes are <em>not</em> case-sensitive; the {@code r} prefix is used to
314f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        distinguish the region portion.
315f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        You cannot specify a region alone.</p>
316f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>This can change during the life
317c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainof your application if the user changes his or her language in the system settings. See <a
318f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhref="runtime-changes.html">Handling Runtime Changes</a> for information about
319f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhow this can affect your application during runtime.</p>
320f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>See <a href="localization.html">Localization</a> for a complete guide to localizing
3217ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainyour application for other languages.</p>
322c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#locale} configuration field, which
323c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainindicates the current locale.</p>
324f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
325f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
3261047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio    <tr id="LayoutDirectionQualifier">
3271047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      <td>Layout Direction</td>
32822d17c984ae91e85a67d3fc03c092538c5080b0fScott Main      <td><code>ldrtl</code><br/>
3291047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio        <code>ldltr</code><br/>
3301047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      </td>
3311047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      <td><p>The layout direction of your application. {@code ldrtl} means "layout-direction-right-to-left".
3321047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      {@code ldltr} means "layout-direction-left-to-right" and is the default implicit value.
3331047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      </p>
33422d17c984ae91e85a67d3fc03c092538c5080b0fScott Main      <p>This can apply to any resource such as layouts, drawables, or values.
3351047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      </p>
3361047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      <p>For example, if you want to provide some specific layout for the Arabic language and some
3371047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      generic layout for any other "right-to-left" language (like Persian or Hebrew) then you would have:
3381047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      </p>
3391047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio<pre class="classic no-pretty-print">
3401047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Megliores/
3411047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio    layout/   <span style="color:black">
34222d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        main.xml  </span>(Default layout)
3431047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio    layout-ar/  <span style="color:black">
34422d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        main.xml  </span>(Specific layout for Arabic)
3451047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio    layout-ldrtl/  <span style="color:black">
34622d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        main.xml  </span>(Any "right-to-left" language, except
34722d17c984ae91e85a67d3fc03c092538c5080b0fScott Main                  for Arabic, because the "ar" language qualifier
34822d17c984ae91e85a67d3fc03c092538c5080b0fScott Main                  has a higher precedence.)
3491047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio</pre>
35022d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        <p class="note"><strong>Note:</strong> To enable right-to-left layout features
35122d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        for your app, you must set <a
35222d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        href="{@docRoot}guide/topics/manifest/application-element.html#supportsrtl">{@code
35322d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        supportsRtl}</a> to {@code "true"} and set <a
35422d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target"
35522d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        >{@code targetSdkVersion}</a> to 17 or higher.</p>
35622d17c984ae91e85a67d3fc03c092538c5080b0fScott Main        <p><em>Added in API level 17.</em></p>
3571047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio      </td>
3581047509e49a7ec1a0fec03352d65567161a99585Fabrice Di Meglio    </tr>
359ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    <tr id="SmallestScreenWidthQualifier">
360759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main      <td>smallestWidth</td>
3619a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main      <td><code>sw&lt;N&gt;dp</code><br/><br/>
3629a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        Examples:<br/>
363ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>sw320dp</code><br/>
364ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>sw600dp</code><br/>
365ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>sw720dp</code><br/>
366ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        etc.
367ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
368ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      <td>
369759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>The fundamental size of a screen, as indicated by the shortest dimension of the available
370759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainscreen area. Specifically, the device's smallestWidth is the shortest of the screen's available
371759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainheight and width (you may also think of it as the "smallest possible width" for the screen). You can
372759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainuse this qualifier to ensure that, regardless of the screen's current orientation, your
3733b9f0aa058e95fa0c998f787a8f4f7225e9850c0kmccormickapplication has at least {@code &lt;N&gt;} dps of width available for its UI.</p>
374759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>For example, if your layout requires that its smallest dimension of screen area be at
375759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainleast 600 dp at all times, then you can use this qualifer to create the layout resources, {@code
376759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainres/layout-sw600dp/}. The system will use these resources only when the smallest dimension of
377759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainavailable screen is at least 600dp, regardless of whether the 600dp side is the user-perceived
378759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainheight or width. The smallestWidth is a fixed screen size characteristic of the device; <strong>the
379759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Maindevice's smallestWidth does not change when the screen's orientation changes</strong>.</p>
380759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>The smallestWidth of a device takes into account screen decorations and system UI. For
381759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainexample, if the device has some persistent UI elements on the screen that account for space along
382759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainthe axis of the smallestWidth, the system declares the smallestWidth to be smaller than the actual
383759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainscreen size, because those are screen pixels not available for your UI. Thus, the value you use
384759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainshould be the actual smallest dimension <em>required by your layout</em> (usually, this value is the
385759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main"smallest width" that your layout supports, regardless of the screen's current orientation).</p>
3869a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>Some values you might use here for common screen sizes:</p>
387ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <ul>
3889a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          <li>320, for devices with screen configurations such as:
3899a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main            <ul>
3909a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main              <li>240x320 ldpi (QVGA handset)</li>
3919a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main              <li>320x480 mdpi (handset)</li>
39264f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe              <li>480x800 hdpi (high-density handset)</li>
3939a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main            </ul>
3949a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          </li>
3959a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          <li>480, for screens such as 480x800 mdpi (tablet/handset).</li>
3969a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          <li>600, for screens such as 600x1024 mdpi (7" tablet).</li>
3979a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          <li>720, for screens such as 720x1280 mdpi (10" tablet).</li>
398ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        </ul>
3999a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>When your application provides multiple resource directories with different values for
400759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        the smallestWidth qualifier, the system uses the one closest to (without exceeding) the
401759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Maindevice's smallestWidth. </p>
4029a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 13.</em></p>
4039a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>Also see the <a
404759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainhref="{@docRoot}guide/topics/manifest/supports-screens-element.html#requiresSmallest">{@code
405759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainandroid:requiresSmallestWidthDp}</a> attribute, which declares the minimum smallestWidth with which
406759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainyour application is compatible, and the {@link
407759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainandroid.content.res.Configuration#smallestScreenWidthDp} configuration field, which holds the
408759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Maindevice's smallestWidth value.</p>
409759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>For more information about designing for different screens and using this
410759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainqualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
411759c89322548dd88b35a3f3b4b5e636c515bbc57Scott MainMultiple Screens</a> developer guide.</p>
412ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
413ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    </tr>
414ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    <tr id="ScreenWidthQualifier">
415db909162b2c26d12f56a7c0615977b83578c4acfScott Main      <td>Available width</td>
4169a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main      <td><code>w&lt;N&gt;dp</code><br/><br/>
4179a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        Examples:<br/>
418ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>w720dp</code><br/>
419ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>w1024dp</code><br/>
420ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        etc.
421ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
422ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      <td>
423db909162b2c26d12f56a7c0615977b83578c4acfScott Main        <p>Specifies a minimum available screen width, in {@code dp} units at which the resource
4249a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          should be used&mdash;defined by the <code>&lt;N&gt;</code> value.  This
4259a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          configuration value will change when the orientation
4269a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          changes between landscape and portrait to match the current actual width.</p>
4279a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>When your application provides multiple resource directories with different values
4289a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          for this configuration, the system uses the one closest to (without exceeding)
4299a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          the device's current screen width.  The
4309a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          value here takes into account screen decorations, so if the device has some
4319a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          persistent UI elements on the left or right edge of the display, it
4329a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          uses a value for the width that is smaller than the real screen size, accounting
4339a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          for these UI elements and reducing the application's available space.</p>
4349a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 13.</em></p>
435ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
436ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn          configuration field, which holds the current screen width.</p>
437759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>For more information about designing for different screens and using this
438759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainqualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
439759c89322548dd88b35a3f3b4b5e636c515bbc57Scott MainMultiple Screens</a> developer guide.</p>
440ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
441ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    </tr>
442ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    <tr id="ScreenHeightQualifier">
443db909162b2c26d12f56a7c0615977b83578c4acfScott Main      <td>Available height</td>
4449a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main      <td><code>h&lt;N&gt;dp</code><br/><br/>
4459a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        Examples:<br/>
446ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>h720dp</code><br/>
447ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <code>h1024dp</code><br/>
448ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        etc.
449ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
450ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      <td>
451db909162b2c26d12f56a7c0615977b83578c4acfScott Main        <p>Specifies a minimum available screen height, in "dp" units at which the resource
4529a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          should be used&mdash;defined by the <code>&lt;N&gt;</code> value.  This
4539a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          configuration value will change when the orientation
4549a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          changes between landscape and portrait to match the current actual height.</p>
4559a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>When your application provides multiple resource directories with different values
4569a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          for this configuration, the system uses the one closest to (without exceeding)
4579a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          the device's current screen height.  The
4589a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          value here takes into account screen decorations, so if the device has some
4599a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          persistent UI elements on the top or bottom edge of the display, it uses
4609a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          a value for the height that is smaller than the real screen size, accounting
4619a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          for these UI elements and reducing the application's available space.  Screen
462ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn          decorations that are not fixed (such as a phone status bar that can be
463ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn          hidden when full screen) are <em>not</em> accounted for here, nor are
4649a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main          window decorations like the title bar or action bar, so applications must be prepared to
465ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn          deal with a somewhat smaller space than they specify.
4669a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 13.</em></p>
467ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
468ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn          configuration field, which holds the current screen width.</p>
469759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Main        <p>For more information about designing for different screens and using this
470759c89322548dd88b35a3f3b4b5e636c515bbc57Scott Mainqualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
471759c89322548dd88b35a3f3b4b5e636c515bbc57Scott MainMultiple Screens</a> developer guide.</p>
472ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn      </td>
473ce67da79e75e8fc601fb8de95a89f88b9cb9b0f3Dianne Hackborn    </tr>
4747ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="ScreenSizeQualifier">
475f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Screen size</td>
476f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
477f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>small</code><br/>
478f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>normal</code><br/>
479ae5335b673be71fe96b8871ea376337d29e01e6eScott Main        <code>large</code><br/>
480ae5335b673be71fe96b8871ea376337d29e01e6eScott Main        <code>xlarge</code>
481f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
482f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
483c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
48444ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <li>{@code small}: Screens that are of similar size to a
48544ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        low-density QVGA screen. The minimum layout size for a small screen
48664f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        is approximately 320x426 dp units.  Examples are QVGA low-density and VGA high
487f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        density.</li>
48844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <li>{@code normal}: Screens that are of similar size to a
48944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        medium-density HVGA screen. The minimum
49044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        layout size for a normal screen is approximately 320x470 dp units.  Examples
49164f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        of such screens a WQVGA low-density, HVGA medium-density, WVGA
49264f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        high-density.</li>
49344ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <li>{@code large}: Screens that are of similar size to a
49444ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        medium-density VGA screen.
49544ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        The minimum layout size for a large screen is approximately 480x640 dp units.
49664f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        Examples are VGA and WVGA medium-density screens.</li>
497ae5335b673be71fe96b8871ea376337d29e01e6eScott Main        <li>{@code xlarge}: Screens that are considerably larger than the traditional
49844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        medium-density HVGA screen. The minimum layout size for an xlarge screen
49964f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        is approximately 720x960 dp units.  In most cases, devices with extra-large
5002f98f2670828a42ef93fe782b5be82b1dfeba6ceDianne Hackborn        screens would be too large to carry in a pocket and would most likely
5019a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        be tablet-style devices. <em>Added in API level 9.</em></li>
502f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        </ul>
50344ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <p class="note"><strong>Note:</strong> Using a size qualifier does not imply that the
50444ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainresources are <em>only</em> for screens of that size. If you do not provide alternative
50544ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainresources with qualifiers that better match the current device configuration, the system may use
50644ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainwhichever resources are the <a href="#BestMatch">best match</a>.</p>
50744ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <p class="caution"><strong>Caution:</strong> If all your resources use a size qualifier that
50844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainis <em>larger</em> than the current screen, the system will <strong>not</strong> use them and your
50944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainapplication will crash at runtime (for example, if all layout resources are tagged with the {@code
51044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainxlarge} qualifier, but the device is a normal-size screen).</p>
5119a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 4.</em></p>
51244ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        
513f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
514f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainScreens</a> for more information.</p>
515c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
516c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates whether the screen is small, normal,
517c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainor large.</p>
518f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
519f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
520821ca51857f4d21b231cd9ead786227b771fe759Scott Main    <tr id="ScreenAspectQualifier">
521821ca51857f4d21b231cd9ead786227b771fe759Scott Main      <td>Screen aspect</td>
522f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
523f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>long</code><br/>
524f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>notlong</code>
525f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
526f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
527c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
528c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code long}: Long screens, such as WQVGA, WVGA, FWVGA</li>
529c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code notlong}: Not long screens, such as QVGA, HVGA, and VGA</li>
530f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        </ul>
5319a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 4.</em></p>
532c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>This is based purely on the aspect ratio of the screen (a "long" screen is wider). This
533c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainis not related to the screen orientation.</p>
534c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
535c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates whether the screen is long.</p>
536f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
537f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
5387ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="OrientationQualifier">
539f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Screen orientation</td>
540f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
541f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>port</code><br/>
542f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>land</code>  <!-- <br/>
543f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>square</code>  -->
544f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
545f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
546c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
547c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code port}: Device is in portrait orientation (vertical)</li>
548c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code land}: Device is in landscape orientation (horizontal)</li>
549c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <!-- Square mode is currently not used. -->
550c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
551f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>This can change during the life of your application if the user rotates the
552f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainscreen. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about
553f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainhow this affects your application during runtime.</p>
554c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#orientation} configuration field,
555c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates the current device orientation.</p>
556f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
557f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
558e302a162359e191633e966520a6bab4ad569390cDianne Hackborn    <tr id="UiModeQualifier">
559e302a162359e191633e966520a6bab4ad569390cDianne Hackborn      <td>UI mode</td>
560f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
561f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>car</code><br/>
562e302a162359e191633e966520a6bab4ad569390cDianne Hackborn        <code>desk</code><br/>
5630cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn        <code>television<br/>
5640cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn        <code>appliance</code>
5656c191299a73388cd593809c0b66bafbd08fd2982John Spurlock        <code>watch</code>
566f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
567f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
568c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
569e302a162359e191633e966520a6bab4ad569390cDianne Hackborn          <li>{@code car}: Device is displaying in a car dock</li>
570e302a162359e191633e966520a6bab4ad569390cDianne Hackborn          <li>{@code desk}: Device is displaying in a desk dock</li>
5710cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          <li>{@code television}: Device is displaying on a television, providing
5720cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          a "ten foot" experience where its UI is on a large screen that the
5730cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          user is far away from, primarily oriented around DPAD or other
5740cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          non-pointer interaction</li>
5750cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          <li>{@code appliance}: Device is serving as an appliance, with
5760cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          no display</li>
5776c191299a73388cd593809c0b66bafbd08fd2982John Spurlock          <li>{@code watch}: Device has a display and is worn on the wrist</li>
578c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
5796c191299a73388cd593809c0b66bafbd08fd2982John Spurlock        <p><em>Added in API level 8, television added in API 13, watch added in API 20.</em></p>
580c73d67f3f1410cac5794dea61676d51e2c36c03aScott Main        <p>For information about how your app can respond when the device is inserted into or
581c73d67f3f1410cac5794dea61676d51e2c36c03aScott Main        removed from a dock, read <a 
582c73d67f3f1410cac5794dea61676d51e2c36c03aScott Main        href="{@docRoot}training/monitoring-device-state/docking-monitoring.html">Determining
583c73d67f3f1410cac5794dea61676d51e2c36c03aScott Mainand Monitoring the Docking State and Type</a>.</p>
584f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>This can change during the life of your application if the user places the device in a
585e302a162359e191633e966520a6bab4ad569390cDianne Hackborndock. You can enable or disable some of these modes using {@link
586c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainandroid.app.UiModeManager}. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
587c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maininformation about how this affects your application during runtime.</p>
588f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
589f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
5907ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="NightQualifier">
591f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Night mode</td>
592f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
593f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>night</code><br/>
594f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>notnight</code>
595f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
596f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
597c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
598c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code night}: Night time</li>
599c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code notnight}: Day time</li>
600c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
6019a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p><em>Added in API level 8.</em></p>
602c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>This can change during the life of your application if night mode is left in
6037ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainauto mode (default), in which case the mode changes based on the time of day.  You can enable
604c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainor disable this mode using {@link android.app.UiModeManager}. See <a
605c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainhref="runtime-changes.html">Handling Runtime Changes</a> for information about how this affects your
606c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainapplication during runtime.</p>
607f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
608f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
6097ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="DensityQualifier">
610f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Screen pixel density (dpi)</td>
611f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
612f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>ldpi</code><br/>
613f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>mdpi</code><br/>
614f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>hdpi</code><br/>
615ae5335b673be71fe96b8871ea376337d29e01e6eScott Main        <code>xhdpi</code><br/>
61664f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        <code>xxhdpi</code><br/>
61764f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        <code>xxxhdpi</code><br/>
61844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <code>nodpi</code><br/>
61944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <code>tvdpi</code>
620f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
621f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
622c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
623c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code ldpi}: Low-density screens; approximately 120dpi.</li>
624c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code mdpi}: Medium-density (on traditional HVGA) screens; approximately
625c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main160dpi.</li>
626c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code hdpi}: High-density screens; approximately 240dpi.</li>
62764f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe          <li>{@code xhdpi}: Extra-high-density screens; approximately 320dpi. <em>Added in API
628ae5335b673be71fe96b8871ea376337d29e01e6eScott MainLevel 8</em></li>
62964f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe          <li>{@code xxhdpi}: Extra-extra-high-density screens; approximately 480dpi. <em>Added in API
63064f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott RoweLevel 16</em></li>
63164f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe          <li>{@code xxxhdpi}: Extra-extra-extra-high-density uses (launcher icon only, see the 
63264f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe            <a href="{@docRoot}guide/practices/screens_support.html#xxxhdpi-note">note</a> 
63364f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe            in <em>Supporting Multiple Screens</em>); approximately 640dpi. <em>Added in API
63464f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott RoweLevel 18</em></li>
635c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code nodpi}: This can be used for bitmap resources that you do not want to be scaled
636c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainto match the device density.</li>
63744ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main          <li>{@code tvdpi}: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is
63844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainnot considered a "primary" density group. It is mostly intended for televisions and most
63944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainapps shouldn't need it&mdash;providing mdpi and hdpi resources is sufficient for most apps and
64044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainthe system will scale them as appropriate. This qualifier was introduced with API level 13.</li>
641c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
64264f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe        <p>There is a 3:4:6:8:12:16 scaling ratio between the six primary densities (ignoring the
64364f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowetvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi, 24x24 in xhdpi and so on.
64464f54c6502f23b2e71f9b0c7789d7ff17c5dfc35Scott Rowe</p>
64544ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <p>If you decide that your image resources don't look good enough on a television or
64644ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainother certain devices and want to try tvdpi resources, the scaling factor is 1.33*mdpi. For
64744ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainexample, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.</p>
64844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main        <p class="note"><strong>Note:</strong> Using a density qualifier does not imply that the
64944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainresources are <em>only</em> for screens of that density. If you do not provide alternative
65044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainresources with qualifiers that better match the current device configuration, the system may use
65144ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainwhichever resources are the <a href="#BestMatch">best match</a>.</p>
652f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
65344ec74db191f88dc22143b55cacc262bc8fc3cd2Scott MainScreens</a> for more information about how to handle different screen densities and how Android
65444ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainmight scale your bitmaps to fit the current density.</p>
655f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main       </td>
656f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
6577ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="TouchscreenQualifier">
658f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Touchscreen type</td>
659f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
660f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>notouch</code><br/>
661f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>finger</code>
662f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
663c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <td>
664c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
665c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code notouch}: Device does not have a touchscreen.</li>
6660cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          <li>{@code finger}: Device has a touchscreen that is intended to
6670cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn          be used through direction interaction of the user's finger.</li>
668c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
669c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#touchscreen} configuration field,
670c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates the type of touchscreen on the device.</p>
671f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
672f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
6737ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="KeyboardAvailQualifier">
674f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Keyboard availability</td>
675f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
676f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>keysexposed</code><br/>
677a84e088211832b6edc0adca2bac407f410ed5788Keiji Ariyama        <code>keyshidden</code><br/>
678f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>keyssoft</code>
679f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
680f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
681c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
682c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code keysexposed}: Device has a keyboard available. If the device has a
683c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainsoftware keyboard enabled (which is likely), this may be used even when the hardware keyboard is
684c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<em>not</em> exposed to the user, even if the device has no hardware keyboard. If no software
685c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainkeyboard is provided or it's disabled, then this is only used when a hardware keyboard is
686c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainexposed.</li>
687c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code keyshidden}: Device has a hardware keyboard available but it is
688c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainhidden <em>and</em> the device does <em>not</em> have a software keyboard enabled.</li>
689c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code keyssoft}: Device has a software keyboard enabled, whether it's
690c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainvisible or not.</li>
691c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
692c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>If you provide <code>keysexposed</code> resources, but not <code>keyssoft</code>
693c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresources, the system uses the <code>keysexposed</code> resources regardless of whether a
694c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainkeyboard is visible, as long as the system has a software keyboard enabled.</p>
695c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>This can change during the life of your application if the user opens a hardware
696c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainkeyboard. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about how
697c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainthis affects your application during runtime.</p>
698c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the configuration fields {@link
699c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainandroid.content.res.Configuration#hardKeyboardHidden} and {@link
700c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainandroid.content.res.Configuration#keyboardHidden}, which indicate the visibility of a hardware
701c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainkeyboard and and the visibility of any kind of keyboard (including software), respectively.</p>
702f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
703f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
7047ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="ImeQualifier">
705f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Primary text input method</td>
706f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
707f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>nokeys</code><br/>
708f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>qwerty</code><br/>
709f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>12key</code>
710f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
711c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <td>
712c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
713c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code nokeys}: Device has no hardware keys for text input.</li>
7147ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main          <li>{@code qwerty}: Device has a hardware qwerty keyboard, whether it's visible to the
7157ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainuser
716c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainor not.</li>
717c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code 12key}: Device has a hardware 12-key keyboard, whether it's visible to the user
718c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainor not.</li>
719c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
720c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#keyboard} configuration field,
721c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates the primary text input method available.</p>
722c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      </td>
723f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
7247ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="NavAvailQualifier">
725f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Navigation key availability</td>
726f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
727f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>navexposed</code><br/>
728f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>navhidden</code>
729f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
730f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
731c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
732c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code navexposed}: Navigation keys are available to the user.</li>
733c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code navhidden}: Navigation keys are not available (such as behind a closed
734c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainlid).</li>
735c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
736f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>This can change during the life of your application if the user reveals the navigation
737f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainkeys. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
738f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maininformation about how this affects your application during runtime.</p>
739c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#navigationHidden} configuration
740c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainfield, which indicates whether navigation keys are hidden.</p>
741f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
742f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
7430cf2c8a53350a800055e76c1c9bf0a6d44480768Dianne Hackborn    <tr id="NavigationQualifier">
744f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Primary non-touch navigation method</td>
745f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
746f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>nonav</code><br/>
747f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>dpad</code><br/>
748f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>trackball</code><br/>
749f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>wheel</code>
750f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
751c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <td>
752c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <ul class="nolist">
753c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code nonav}: Device has no navigation facility other than using the
754c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maintouchscreen.</li>
755c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code dpad}: Device has a directional-pad (d-pad) for navigation.</li>
756c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code trackball}: Device has a trackball for navigation.</li>
757c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main          <li>{@code wheel}: Device has a directional wheel(s) for navigation (uncommon).</li>
758c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        </ul>
759c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main        <p>Also see the {@link android.content.res.Configuration#navigation} configuration field,
760c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainwhich indicates the type of navigation method available.</p>
761f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
762f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
763f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<!-- DEPRECATED
764f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <tr>
765f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Screen dimensions</td>
766f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Examples:<br/>
767f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>320x240</code><br/>
768f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>640x480</code><br/>
769f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        etc.
770f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
771f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
772f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <p>The larger dimension must be specified first. <strong>This configuration is deprecated
773f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainand should not be used</strong>. Instead use "screen size," "wider/taller screens," and "screen
774f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainorientation" described above.</p>
775f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
776f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
777f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main-->
7787ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main    <tr id="VersionQualifier">
7799a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main      <td>Platform Version (API level)</td>
780f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>Examples:<br/>
7817ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main        <code>v3</code><br/>
782f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>v4</code><br/>
783f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <code>v7</code><br/>
784f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        etc.</td>
785f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <td>
7869a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main        <p>The API level supported by the device. For example, <code>v1</code> for API level
7879a05cfe5427a6cee988333e0d65f17b9854554a3Scott Main1 (devices with Android 1.0 or higher) and <code>v4</code> for API level 4 (devices with Android
7887ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main1.6 or higher). See the <a
78950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainhref="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">Android API levels</a> document for more information
790f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainabout these values.</p>
791f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </td>
792f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </tr>
793f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</table>
794f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
795c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
796be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main<p class="note"><strong>Note:</strong> Some configuration qualifiers have been added since Android
797be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main1.0, so not all versions of Android support all the qualifiers. Using a new qualifier implicitly
798be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainadds the platform version qualifier so that older devices are sure to ignore it. For example, using
799be0cf70dc3ff77661dbdf416d415757f2500e889Scott Maina <code>w600dp</code> qualifier will automatically include the <code>v13</code> qualifier, because
800be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainthe available-width qualifier was new in API level 13. To avoid any issues, always include a set of
801be0cf70dc3ff77661dbdf416d415757f2500e889Scott Maindefault resources (a set of resources with <em>no qualifiers</em>). For more information, see the
802be0cf70dc3ff77661dbdf416d415757f2500e889Scott Mainsection about <a href="#Compatibility">Providing the Best Device Compatibility with
803be0cf70dc3ff77661dbdf416d415757f2500e889Scott MainResources</a>.</p>
804be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main
805be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main
806be0cf70dc3ff77661dbdf416d415757f2500e889Scott Main
807c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<h3 id="QualifierRules">Qualifier name rules</h3>
808c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
809821ca51857f4d21b231cd9ead786227b771fe759Scott Main<p>Here are some rules about using configuration qualifier names:</p>
810f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
811f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<ul>
812f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li>You can specify multiple qualifiers for a single set of resources, separated by dashes. For
813f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainexample, <code>drawable-en-rUS-land</code> applies to US-English devices in landscape
814f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainorientation.</li>
815c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <li>The qualifiers must be in the order listed in <a href="#table2">table 2</a>. For
816f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainexample:
817f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      <ul>
818f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Wrong: <code>drawable-hdpi-port/</code></li>
819f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main        <li>Correct: <code>drawable-port-hdpi/</code></li>
820f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main      </ul>
821f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </li>
822c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <li>Alternative resource directories cannot be nested. For example, you cannot have
823f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<code>res/drawable/drawable-en/</code>.</li>
824f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li>Values are case-insensitive.  The resource compiler converts directory names
825f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    to lower case before processing to avoid problems on case-insensitive
826f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    file systems. Any capitalization in the names is only to benefit readability.</li>
827f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <li>Only one value for each qualifier type is supported. For example, if you want to use
828f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainthe same drawable files for Spain and France, you <em>cannot</em> have a directory named
829f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<code>drawable-rES-rFR/</code>. Instead you need two resource directories, such as
830f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<code>drawable-rES/</code> and <code>drawable-rFR/</code>, which contain the appropriate files.
831c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainHowever, you are not required to actually duplicate the same files in both locations. Instead, you
832c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maincan create an alias to a resource. See <a href="#AliasResources">Creating
833c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainalias resources</a> below.</li>
834f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</ul>
835f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
836c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>After you save alternative resources into directories named with
837c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainthese qualifiers, Android automatically applies the resources in your application based on the
838c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maincurrent device configuration. Each time a resource is requested, Android checks for alternative
839c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresource directories that contain the requested resource file, then <a href="#BestMatch">finds the
840821ca51857f4d21b231cd9ead786227b771fe759Scott Mainbest-matching resource</a> (discussed below). If there are no alternative resources that match
841821ca51857f4d21b231cd9ead786227b771fe759Scott Maina particular device configuration, then Android uses the corresponding default resources (the
842821ca51857f4d21b231cd9ead786227b771fe759Scott Mainset of resources for a particular resource type that does not include a configuration
843821ca51857f4d21b231cd9ead786227b771fe759Scott Mainqualifier).</p>
844c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
845f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
846f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
847f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h3 id="AliasResources">Creating alias resources</h3>
848f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
849f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>When you have a resource that you'd like to use for more than one device
850821ca51857f4d21b231cd9ead786227b771fe759Scott Mainconfiguration (but do not want to provide as a default resource), you do not need to put the same
851821ca51857f4d21b231cd9ead786227b771fe759Scott Mainresource in more than one alternative resource directory. Instead, you can (in some cases) create an
852821ca51857f4d21b231cd9ead786227b771fe759Scott Mainalternative
853f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainresource that acts as an alias for a resource saved in your default resource directory.</p>
854f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
855c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p class="note"><strong>Note:</strong> Not all resources offer a mechanism by which you can
856c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maincreate an alias to another resource. In particular, animation, menu, raw, and other unspecified
857c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainresources in the {@code xml/} directory do not offer this feature.</p>
858c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
859c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>For example, imagine you have an application icon, {@code icon.png}, and need unique version of
860c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainit for different locales. However, two locales, English-Canadian and French-Canadian, need to
861c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainuse the same version. You might assume that you need to copy the same image
862c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maininto the resource directory for both English-Canadian and French-Canadian, but it's
863c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainnot true. Instead, you can save the image that's used for both as {@code icon_ca.png} (any
864c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainname other than {@code icon.png}) and put
865f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainit in the default {@code res/drawable/} directory. Then create an {@code icon.xml} file in {@code
866f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainres/drawable-en-rCA/} and {@code res/drawable-fr-rCA/} that refers to the {@code icon_ca.png}
867f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainresource using the {@code &lt;bitmap&gt;} element. This allows you to store just one version of the
868f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainPNG file and two small XML files that point to it. (An example XML file is shown below.)</p>
869f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
870f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
871f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h4>Drawable</h4>
872f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
873f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>To create an alias to an existing drawable, use the {@code &lt;bitmap&gt;} element.
874f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainFor example:</p>
875f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
876f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<pre>
877f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;?xml version="1.0" encoding="utf-8"?>
878f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android"
879f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    android:src="@drawable/icon_ca" />
880f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
881f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
882c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>If you save this file as {@code icon.xml} (in an alternative resource directory, such as
883c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main{@code res/drawable-en-rCA/}), it is compiled into a resource that you
884f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maincan reference as {@code R.drawable.icon}, but is actually an alias for the {@code
885c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainR.drawable.icon_ca} resource (which is saved in {@code res/drawable/}).</p>
886f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
887f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
888f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h4>Layout</h4>
889f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
890f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>To create an alias to an existing layout, use the {@code &lt;include&gt;}
891f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainelement, wrapped in a {@code &lt;merge&gt;}. For example:</p>
892f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
893f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<pre>
894f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;?xml version="1.0" encoding="utf-8"?>
895f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;merge>
896f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    &lt;include layout="@layout/main_ltr"/>
897f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;/merge>
898f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
899f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
900c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>If you save this file as {@code main.xml}, it is compiled into a resource you can reference
901f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainas {@code R.layout.main}, but is actually an alias for the {@code R.layout.main_ltr}
902f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainresource.</p>
903f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
904f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
905f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h4>Strings and other simple values</h4>
906f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
907f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>To create an alias to an existing string, simply use the resource ID of the desired
908f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainstring as the value for the new string. For example:</p>
909f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
910f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<pre>
911f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;?xml version="1.0" encoding="utf-8"?>
912f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;resources>
913f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    &lt;string name="hello">Hello&lt;/string>
914f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    &lt;string name="hi">@string/hello&lt;/string>
915f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;/resources>
916f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
917f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
918f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>The {@code R.string.hi} resource is now an alias for the {@code R.string.hello}.</p>
919f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
920f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p> <a href="{@docRoot}guide/topics/resources/more-resources.html">Other simple values</a> work the
921f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainsame way. For example, a color:</p>
922f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
923f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<pre>
924f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;?xml version="1.0" encoding="utf-8"?>
925f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;resources>
926f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    &lt;color name="yellow">#f00&lt;/color>
927f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    &lt;color name="highlight">@color/red&lt;/color>
928f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main&lt;/resources>
929f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
930f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
931f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
932f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
933f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
9347ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<h2 id="Compatibility">Providing the Best Device Compatibility with Resources</h2>
9357ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
9367ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>In order for your application to support multiple device configurations, it's very important that
9377ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainyou always provide default resources for each type of resource that your application uses.</p>
9387ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
9397ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>For example, if your application supports several languages, always include a {@code
9407ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainvalues/} directory (in which your strings are saved) <em>without</em> a <a
941369c1c1fa22802b6504c5cde533d797841700a66Scott Mainhref="#LocaleQualifier">language and region qualifier</a>. If you instead put all your string files
9427ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainin directories that have a language and region qualifier, then your application will crash when run
9437ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainon a device set to a language that your strings do not support. But, as long as you provide default
9447ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main{@code values/} resources, then your application will run properly (even if the user doesn't
9457ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainunderstand that language&mdash;it's better than crashing).</p>
9467ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
9477ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>Likewise, if you provide different layout resources based on the screen orientation, you should
9487ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainpick one orientation as your default. For example, instead of providing layout resources in {@code
9497ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainlayout-land/} for landscape and {@code layout-port/} for portrait, leave one as the default, such as
9507ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main{@code layout/} for landscape and {@code layout-port/} for portrait.</p>
9517ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
9527ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>Providing default resources is important not only because your application might run on a
9537ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainconfiguration you had not anticipated, but also because new versions of Android sometimes add
954821ca51857f4d21b231cd9ead786227b771fe759Scott Mainconfiguration qualifiers that older versions do not support. If you use a new resource qualifier,
9557ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainbut maintain code compatibility with older versions of Android, then when an older version of
9567ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott MainAndroid runs your application, it will crash if you do not provide default resources, because it
9577ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maincannot use the resources named with the new qualifier. For example, if your <a
9587ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainhref="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
9597ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott MainminSdkVersion}</a> is set to 4, and you qualify all of your drawable resources using <a
9601c8b6ca4d7dd7c8263d5224de6e814681a14afa5Scott Mainhref="#NightQualifier">night mode</a> ({@code night} or {@code notnight}, which were added in API
9619a05cfe5427a6cee988333e0d65f17b9854554a3Scott MainLevel 8), then an API level 4 device cannot access your drawable resources and will crash. In this
9627ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maincase, you probably want {@code notnight} to be your default resources, so you should exclude that
9637ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainqualifier so your drawable resources are in either {@code drawable/} or {@code drawable-night/}.</p>
9647ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
965821ca51857f4d21b231cd9ead786227b771fe759Scott Main<p>So, in order to provide the best device compatibility, always provide default
966821ca51857f4d21b231cd9ead786227b771fe759Scott Mainresources for the resources your application needs to perform properly. Then create alternative
967821ca51857f4d21b231cd9ead786227b771fe759Scott Mainresources for specific device configurations using the configuration qualifiers.</p>
9687ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
9697ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main<p>There is one exception to this rule: If your application's <a
9707ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainhref="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> is 4 or
9717ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maingreater, you <em>do not</em> need default drawable resources when you provide alternative drawable
9727ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainresources with the <a href="#DensityQualifier">screen density</a> qualifier. Even without default
9737ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Maindrawable resources, Android can find the best match among the alternative screen densities and scale
9747ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Mainthe bitmaps as necessary. However, for the best experience on all types of devices, you should
975c89312091e291c3e0cdb3cb7df3f76250fce7d22Scott Mainprovide alternative drawables for all three types of density.</p>
976821ca51857f4d21b231cd9ead786227b771fe759Scott Main
9777ef674b596ba1bac6b26350a6c478d5e6a16bfd7Scott Main
978f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
979f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<h2 id="BestMatch">How Android Finds the Best-matching Resource</h2>
980f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
981c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>When you request a resource for which you provide alternatives, Android selects which
982c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainalternative resource to use at runtime, depending on the current device configuration. To
983c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindemonstrate how Android selects an alternative resource, assume the following drawable directories
984c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maineach contain different versions of the same images:</p>
985c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
986c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
987c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable/
988c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-en/
989c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-fr-rCA/
990c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-en-port/
991c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-en-notouch-12key/
992c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-port-ldpi/
993c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-port-notouch-12key/
994f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
995f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
996f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p>And assume the following is the device configuration:</p>
997f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
998c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p style="margin-left:1em;">
999f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainLocale = <code>en-GB</code> <br/>
1000f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainScreen orientation = <code>port</code> <br/>
1001f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainScreen pixel density = <code>hdpi</code> <br/>
1002f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainTouchscreen type = <code>notouch</code> <br/>
1003f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainPrimary text input method = <code>12key</code>
1004f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</p>
1005f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1006c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>By comparing the device configuration to the available alternative resources, Android selects
100744ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Maindrawables from {@code drawable-en-port}.</p>
100844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main
100944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main<p>The system arrives at its decision for which resources to use with the following
101044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainlogic:</p>
1011c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
1012c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
1013e63163a3349a542fcdefbf793a87696b6cbea3d8Scott Main<div class="figure" style="width:371px">
1014e63163a3349a542fcdefbf793a87696b6cbea3d8Scott Main<img src="{@docRoot}images/resources/res-selection-flowchart.png" alt="" height="471" />
1015c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p class="img-caption"><strong>Figure 2.</strong> Flowchart of how Android finds the
1016c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainbest-matching resource.</p>
1017c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main</div>
1018f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1019f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1020f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<ol>
1021f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <li>Eliminate resource files that contradict the device configuration.
1022c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main    <p>The <code>drawable-fr-rCA/</code> directory is eliminated, because it
1023c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maincontradicts the <code>en-GB</code> locale.</p>
1024c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
1025f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable/
1026f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en/
1027f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<strike>drawable-fr-rCA/</strike>
1028f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en-port/
1029f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en-notouch-12key/
1030f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-port-ldpi/
1031c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maindrawable-port-notouch-12key/
1032f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
1033c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p class="note"><strong>Exception:</strong> Screen pixel density is the one qualifier that is not
1034c09a6977ae3922522dd59ff4fcb84f329f0d695cGilles Debunneeliminated due to a contradiction. Even though the screen density of the device is hdpi,
1035f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<code>drawable-port-ldpi/</code> is not eliminated because every screen density is
1036c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainconsidered to be a match at this point. More information is available in the <a
1037c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainhref="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1038c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainScreens</a> document.</p></li>
1039f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1040c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main  <li>Pick the (next) highest-precedence qualifier in the list (<a href="#table2">table 2</a>).
1041c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main(Start with MCC, then move down.) </li>
1042c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main  <li>Do any of the resource directories include this qualifier?  </li>
1043f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    <ul>
1044c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <li>If No, return to step 2 and look at the next qualifier. (In the example,
1045c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main  the answer is &quot;no&quot; until the language qualifier is reached.)</li>
1046c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main      <li>If Yes, continue to step 4.</li>
1047f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main    </ul>
1048f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </li>
1049f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1050f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  <li>Eliminate resource directories that do not include this qualifier. In the example, the system
1051f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maineliminates all the directories that do not include a language qualifier:</li>
1052c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
1053f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<strike>drawable/</strike>
1054f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en/
1055f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en-port/
1056f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en-notouch-12key/
1057f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<strike>drawable-port-ldpi/</strike>
1058c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<strike>drawable-port-notouch-12key/</strike>
1059f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
1060f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p class="note"><strong>Exception:</strong> If the qualifier in question is screen pixel density,
1061c09a6977ae3922522dd59ff4fcb84f329f0d695cGilles DebunneAndroid selects the option that most closely matches the device screen density.
1062c09a6977ae3922522dd59ff4fcb84f329f0d695cGilles DebunneIn general, Android prefers scaling down a larger original image to scaling up a smaller
1063c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainoriginal image. See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1064c6cb8a78d03cda44a49a990b4d4153560bee7420Scott MainScreens</a>.</p>
1065f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </li>
1066f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1067c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main  <li>Go back and repeat steps 2, 3, and 4 until only one directory remains. In the example, screen
1068f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainorientation is the next qualifier for which there are any matches.
1069f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott MainSo, resources that do not specify a screen orientation are eliminated:
1070c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<pre class="classic no-pretty-print">
1071f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<strike>drawable-en/</strike>
1072f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maindrawable-en-port/
1073f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<strike>drawable-en-notouch-12key/</strike>
1074f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</pre>
1075c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>The remaining directory is {@code drawable-en-port}.</p>
1076f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main  </li>
1077f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main</ol>
1078f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
1079c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>Though this procedure is executed for each resource requested, the system further optimizes
1080f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainsome aspects. One such optimization is that once the device configuration is known, it might
1081c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Maineliminate alternative resources that can never match. For example, if the configuration
1082f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainlanguage is English ("en"), then any resource directory that has a language qualifier set to
1083c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainsomething other than English is never included in the pool of resources checked (though a
1084f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainresource directory <em>without</em> the language qualifier is still included).</p>
1085f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main
108644ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main<p>When selecting resources based on the screen size qualifiers, the system will use resources
108744ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Maindesigned for a screen smaller than the current screen if there are no resources that better match
108844ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main(for example, a large-size screen will use normal-size screen resources if necessary). However, if
108944ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainthe only available resources are <em>larger</em> than the current screen, the system will
109044ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main<strong>not</strong> use them and your application will crash if no other resources match the device
109144ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainconfiguration (for example, if all layout resources are tagged with the {@code xlarge} qualifier,
109244ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Mainbut the device is a normal-size screen).</p>
109344ec74db191f88dc22143b55cacc262bc8fc3cd2Scott Main
1094f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main<p class="note"><strong>Note:</strong> The <em>precedence</em> of the qualifier (in <a
1095c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainhref="#table2">table 2</a>) is more important
1096f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainthan the number of qualifiers that exactly match the device. For example, in step 4 above, the last
1097f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Mainchoice on the list includes three qualifiers that exactly match the device (orientation, touchscreen
1098f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Maintype, and input method), while <code>drawable-en</code> has only one parameter that matches
1099f940a1f316ddbed760f6f3ab9a3e4f2112909381Scott Main(language). However, language has a higher precedence than these other qualifiers, so
1100c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<code>drawable-port-notouch-12key</code> is out.</p>
1101c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main
1102c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Main<p>To learn more about how to use resources in your application, continue to <a
1103c6cb8a78d03cda44a49a990b4d4153560bee7420Scott Mainhref="accessing-resources.html">Accessing Resources</a>.</p>
1104