blob: 77e8d7720c61c61c8eac88383af51046345cf097 [file] [log] [blame]
Scott Mainf940a1f2010-02-09 18:48:27 -08001page.title=Providing Resources
2parent.title=Application Resources
3parent.link=index.html
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8 <h2>Quickview</h2>
9 <ul>
Scott Mainc6cb8a72010-04-09 15:52:18 -070010 <li>Different types of resources belong in different subdirectories of {@code res/}</li>
Scott Mainf940a1f2010-02-09 18:48:27 -080011 <li>Alternative resources provide configuration-specific resource files</li>
Scott Main821ca512010-06-16 11:06:43 -070012 <li>Always include default resources so your app does not depend on specific
13device configurations</li>
Scott Mainf940a1f2010-02-09 18:48:27 -080014 </ul>
15 <h2>In this document</h2>
16 <ol>
Scott Mainc6cb8a72010-04-09 15:52:18 -070017 <li><a href="#ResourceTypes">Grouping Resource Types</a></li>
Scott Mainf940a1f2010-02-09 18:48:27 -080018 <li><a href="#AlternativeResources">Providing Alternative Resources</a>
19 <ol>
Scott Mainc6cb8a72010-04-09 15:52:18 -070020 <li><a href="#QualifierRules">Qualifier name rules</a></li>
Scott Mainf940a1f2010-02-09 18:48:27 -080021 <li><a href="#AliasResources">Creating alias resources</a></li>
22 </ol>
23 </li>
Scott Mainc8931202013-05-06 16:38:42 -070024 <li><a href="#Compatibility">Providing the Best Device Compatibility with Resources</a></li>
Scott Mainf940a1f2010-02-09 18:48:27 -080025 <li><a href="#BestMatch">How Android Finds the Best-matching Resource</a></li>
26 </ol>
27
28 <h2>See also</h2>
29 <ol>
30 <li><a href="accessing-resources.html">Accessing Resources</a></li>
31 <li><a href="available-resources.html">Resource Types</a></li>
Scott Mainc6cb8a72010-04-09 15:52:18 -070032 <li><a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
33Screens</a></li>
Scott Mainf940a1f2010-02-09 18:48:27 -080034 </ol>
35</div>
36</div>
37
Scott Mainc6cb8a72010-04-09 15:52:18 -070038<p>You should always externalize application resources such as images and strings from your
Scott Main821ca512010-06-16 11:06:43 -070039code, so that you can maintain them independently. You should also provide alternative resources for
40specific device configurations, by grouping them in specially-named resource directories. At
Scott Main50e990c2012-06-21 17:14:39 -070041runtime, Android uses the appropriate resource based on the current configuration. For
Scott Main821ca512010-06-16 11:06:43 -070042example, you might want to provide a different UI layout depending on the screen size or different
43strings depending on the language setting.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -080044
Scott Main7ef674b2010-06-10 18:05:13 -070045<p>Once you externalize your application resources, you can access them
Scott Mainc6cb8a72010-04-09 15:52:18 -070046using resource IDs that are generated in your project's {@code R} class. How to use
47resources in your application is discussed in <a href="accessing-resources.html">Accessing
Scott Main7ef674b2010-06-10 18:05:13 -070048Resources</a>. This document shows you how to group your resources in your Android project and
49provide alternative resources for specific device configurations.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -080050
Scott Mainc6cb8a72010-04-09 15:52:18 -070051
52<h2 id="ResourceTypes">Grouping Resource Types</h2>
53
54<p>You should place each type of resource in a specific subdirectory of your project's
55{@code res/} directory. For example, here's the file hierarchy for a simple project:</p>
56
57<pre class="classic no-pretty-print">
Scott Mainf940a1f2010-02-09 18:48:27 -080058MyProject/
59 src/ <span style="color:black">
60 MyActivity.java </span>
61 res/
62 drawable/ <span style="color:black">
Rich Slogar69223702015-02-09 11:40:44 -080063 graphic.png </span>
Scott Mainf940a1f2010-02-09 18:48:27 -080064 layout/ <span style="color:black">
Scott Mainc6cb8a72010-04-09 15:52:18 -070065 main.xml
66 info.xml</span>
Rich Slogar69223702015-02-09 11:40:44 -080067 mipmap/ <span style="color:black">
68 icon.png </span>
Scott Mainf940a1f2010-02-09 18:48:27 -080069 values/ <span style="color:black">
70 strings.xml </span>
71</pre>
72
Scott Main7ef674b2010-06-10 18:05:13 -070073<p>As you can see in this example, the {@code res/} directory contains all the resources (in
Rich Slogar69223702015-02-09 11:40:44 -080074subdirectories): an image resource, two layout resources, {@code mipmap/} directories for launcher
75icons, and a string resource file. The resource
Scott Main7ef674b2010-06-10 18:05:13 -070076directory names are important and are described in table 1.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -080077
Rich Slogar69223702015-02-09 11:40:44 -080078<p class="note"><strong>Note:</strong> For more information about using the mipmap folders, see
Rich Slogar0f44b942015-02-19 10:48:37 -080079<a href="{@docRoot}tools/projects/index.html#mipmap">Managing Projects Overview</a>.</p>
Rich Slogar69223702015-02-09 11:40:44 -080080
Scott Mainc6cb8a72010-04-09 15:52:18 -070081<p class="table-caption" id="table1"><strong>Table 1.</strong> Resource directories
82supported inside project {@code res/} directory.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -080083
84<table>
85 <tr>
86 <th scope="col">Directory</th>
Scott Mainc6cb8a72010-04-09 15:52:18 -070087 <th scope="col">Resource Type</th>
Scott Mainf940a1f2010-02-09 18:48:27 -080088 </tr>
89
90 <tr>
Scott Main99960b72011-05-17 17:00:58 -070091 <td><code>animator/</code></td>
Scott Main50e990c2012-06-21 17:14:39 -070092 <td>XML files that define <a href="{@docRoot}guide/topics/graphics/prop-animation.html">property
Scott Main99960b72011-05-17 17:00:58 -070093animations</a>.</td>
94 </tr>
95
96 <tr>
Scott Mainf940a1f2010-02-09 18:48:27 -080097 <td><code>anim/</code></td>
Scott Main99960b72011-05-17 17:00:58 -070098 <td>XML files that define <a
99href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">tween
100animations</a>. (Property animations can also be saved in this directory, but
101the {@code animator/} directory is preferred for property animations to distinguish between the two
102types.)</td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800103 </tr>
104
105 <tr>
106 <td><code>color/</code></td>
107 <td>XML files that define a state list of colors. See <a href="color-list-resource.html">Color
Scott Mainc6cb8a72010-04-09 15:52:18 -0700108State List Resource</a></td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800109 </tr>
110
111 <tr>
112 <td><code>drawable/</code></td>
Rich Slogar69223702015-02-09 11:40:44 -0800113
Scott Mainf940a1f2010-02-09 18:48:27 -0800114 <td><p>Bitmap files ({@code .png}, {@code .9.png}, {@code .jpg}, {@code .gif}) or XML files that
Scott Mainc6cb8a72010-04-09 15:52:18 -0700115are compiled into the following drawable resource subtypes:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800116 <ul>
117 <li>Bitmap files</li>
118 <li>Nine-Patches (re-sizable bitmaps)</li>
119 <li>State lists</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800120 <li>Shapes</li>
121 <li>Animation drawables</li>
Scott Main7ef674b2010-06-10 18:05:13 -0700122 <li>Other drawables</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800123 </ul>
124 <p>See <a href="drawable-resource.html">Drawable Resources</a>.</p>
125 </td>
126 </tr>
127
128 <tr>
Rich Slogar69223702015-02-09 11:40:44 -0800129 <td><code>mipmap/</code></td>
130 <td>Drawable files for different launcher icon densities. For more information on managing
131 launcher icons with {@code mipmap/} folders, see
Rich Slogar16c24582015-04-23 12:44:38 -0700132 <a href="{@docRoot}tools/projects/index.html#mipmap">Managing Projects Overview</a>.</td>
Rich Slogar69223702015-02-09 11:40:44 -0800133 </tr>
134
135 <tr>
Scott Mainf940a1f2010-02-09 18:48:27 -0800136 <td><code>layout/</code></td>
137 <td>XML files that define a user interface layout.
138 See <a href="layout-resource.html">Layout Resource</a>.</td>
139 </tr>
140
141 <tr>
142 <td><code>menu/</code></td>
143 <td>XML files that define application menus, such as an Options Menu, Context Menu, or Sub
144Menu. See <a href="menu-resource.html">Menu Resource</a>.</td>
145 </tr>
146
147 <tr>
148 <td><code>raw/</code></td>
Dianne Hackborn7025d8e2010-11-01 09:49:37 -0700149 <td><p>Arbitrary files to save in their raw form. To open these resources with a raw
150{@link java.io.InputStream}, call {@link android.content.res.Resources#openRawResource(int)
Neil Fuller71fbb812015-11-30 09:51:33 +0000151Resources.openRawResource()} with the resource ID, which is <code>R.raw.<em>filename</em></code>.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700152 <p>However, if you need access to original file names and file hierarchy, you might consider
153saving some resources in the {@code
154assets/} directory (instead of {@code res/raw/}). Files in {@code assets/} are not given a
155resource ID, so you can read them only using {@link android.content.res.AssetManager}.</p></td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800156 </tr>
157
158 <tr>
159 <td><code>values/</code></td>
160 <td><p>XML files that contain simple values, such as strings, integers, and colors.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700161 <p>Whereas XML resource files in other {@code res/} subdirectories define a single resource
162based on the XML filename, files in the {@code values/} directory describe multiple resources.
Neil Fuller71fbb812015-11-30 09:51:33 +0000163For a file in this directory, each child of the {@code <resources>} element defines a single
164resource. For example, a {@code <string>} element creates an
165{@code R.string} resource and a {@code <color>} element creates an {@code R.color}
Scott Mainf940a1f2010-02-09 18:48:27 -0800166resource.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700167 <p>Because each resource is defined with its own XML element, you can name the file
168whatever you want and place different resource types in one file. However, for clarity, you might
169want to place unique resource types in different files. For example, here are some filename
170conventions for resources you can create in this directory:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800171 <ul>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700172 <li>arrays.xml for resource arrays (<a
Scott Mainf940a1f2010-02-09 18:48:27 -0800173href="more-resources.html#TypedArray">typed arrays</a>).</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700174 <li>colors.xml for <a
Scott Mainf940a1f2010-02-09 18:48:27 -0800175href="more-resources.html#Color">color values</a></li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700176 <li>dimens.xml for <a
Scott Mainf940a1f2010-02-09 18:48:27 -0800177href="more-resources.html#Dimension">dimension values</a>.</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700178 <li>strings.xml for <a href="string-resource.html">string
Scott Mainf940a1f2010-02-09 18:48:27 -0800179values</a>.</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700180 <li>styles.xml for <a href="style-resource.html">styles</a>.</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800181 </ul>
182 <p>See <a href="string-resource.html">String Resources</a>,
183 <a href="style-resource.html">Style Resource</a>, and
184 <a href="more-resources.html">More Resource Types</a>.</p>
185 </td>
186 </tr>
187
188 <tr>
189 <td><code>xml/</code></td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700190 <td>Arbitrary XML files that can be read at runtime by calling {@link
Scott Mainf940a1f2010-02-09 18:48:27 -0800191android.content.res.Resources#getXml(int) Resources.getXML()}. Various XML configuration files
Scott Mainc6cb8a72010-04-09 15:52:18 -0700192must be saved here, such as a <a
Scott Mainf940a1f2010-02-09 18:48:27 -0800193href="{@docRoot}guide/topics/search/searchable-config.html">searchable configuration</a>.
194<!-- or preferences configuration. --></td>
195 </tr>
196</table>
197
Scott Main7ef674b2010-06-10 18:05:13 -0700198<p class="caution"><strong>Caution:</strong> Never save resource files directly inside the
199{@code res/} directory&mdash;it will cause a compiler error.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700200
Scott Mainf940a1f2010-02-09 18:48:27 -0800201<p>For more information about certain types of resources, see the <a
202href="available-resources.html">Resource Types</a> documentation.</p>
203
Scott Main7ef674b2010-06-10 18:05:13 -0700204<p>The resources that you save in the subdirectories defined in table 1 are your "default"
205resources. That is, these resources define the default design and content for your application.
206However, different types of Android-powered devices might call for different types of resources.
207For example, if a device has a larger than normal screen, then you should provide
208different layout resources that take advantage of the extra screen space. Or, if a device has a
209different language setting, then you should provide different string resources that translate the
210text in your user interface. To provide these different resources for different device
Scott Main821ca512010-06-16 11:06:43 -0700211configurations, you need to provide alternative resources, in addition to your default
Scott Main7ef674b2010-06-10 18:05:13 -0700212resources.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800213
214
215<h2 id="AlternativeResources">Providing Alternative Resources</h2>
216
217
Scott Maine63163a2012-01-03 10:10:21 -0800218<div class="figure" style="width:429px">
219<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="167" alt="" />
Scott Mainf940a1f2010-02-09 18:48:27 -0800220<p class="img-caption">
Scott Maine63163a2012-01-03 10:10:21 -0800221<strong>Figure 1.</strong> Two different devices, each using different layout resources.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800222</div>
223
224<p>Almost every application should provide alternative resources to support specific device
Scott Mainc6cb8a72010-04-09 15:52:18 -0700225configurations. For instance, you should include alternative drawable resources for different
226screen densities and alternative string resources for different languages. At runtime, Android
Scott Main7ef674b2010-06-10 18:05:13 -0700227detects the current device configuration and loads the appropriate
228resources for your application.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800229
Scott Mainc6cb8a72010-04-09 15:52:18 -0700230<p>To specify configuration-specific alternatives for a set of resources:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800231<ol>
Neil Fuller71fbb812015-11-30 09:51:33 +0000232 <li>Create a new directory in {@code res/} named in the form
233 <code><em>&lt;resources_name&gt;</em>-<em>&lt;config_qualifier&gt;</em></code>.
Scott Mainf940a1f2010-02-09 18:48:27 -0800234 <ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000235 <li><em>{@code <resources_name>}</em> is the directory name of the corresponding default
Scott Main7ef674b2010-06-10 18:05:13 -0700236resources (defined in table 1).</li>
Neil Fuller71fbb812015-11-30 09:51:33 +0000237 <li><em>{@code <qualifier>}</em> is a name that specifies an individual configuration
Scott Main7ef674b2010-06-10 18:05:13 -0700238for which these resources are to be used (defined in table 2).</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800239 </ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000240 <p>You can append more than one <em>{@code <qualifier>}</em>. Separate each
Scott Mainf940a1f2010-02-09 18:48:27 -0800241one with a dash.</p>
Scott Mainbe0cf702012-01-13 11:13:13 -0800242 <p class="caution"><strong>Caution:</strong> When appending multiple qualifiers, you must
243place them in the same order in which they are listed in table 2. If the qualifiers are ordered
244wrong, the resources are ignored.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800245 </li>
Scott Main7ef674b2010-06-10 18:05:13 -0700246 <li>Save the respective alternative resources in this new directory. The resource files must be
247named exactly the same as the default resource files.</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800248</ol>
249
250<p>For example, here are some default and alternative resources:</p>
251
Scott Mainc6cb8a72010-04-09 15:52:18 -0700252<pre class="classic no-pretty-print">
Scott Mainf940a1f2010-02-09 18:48:27 -0800253res/
254 drawable/ <span style="color:black">
255 icon.png
256 background.png </span>
257 drawable-hdpi/ <span style="color:black">
258 icon.png
259 background.png </span>
260</pre>
261
Scott Mainc6cb8a72010-04-09 15:52:18 -0700262<p>The {@code hdpi} qualifier indicates that the resources in that directory are for devices with a
Scott Main7ef674b2010-06-10 18:05:13 -0700263high-density screen. The images in each of these drawable directories are sized for a specific
264screen density, but the filenames are exactly
Scott Mainc6cb8a72010-04-09 15:52:18 -0700265the same. This way, the resource ID that you use to reference the {@code icon.png} or {@code
266background.png} image is always the same, but Android selects the
Scott Main7ef674b2010-06-10 18:05:13 -0700267version of each resource that best matches the current device, by comparing the device
Scott Mainbe0cf702012-01-13 11:13:13 -0800268configuration information with the qualifiers in the resource directory name.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800269
270<p>Android supports several configuration qualifiers and you can
Scott Mainc6cb8a72010-04-09 15:52:18 -0700271add multiple qualifiers to one directory name, by separating each qualifier with a dash. Table 2
272lists the valid configuration qualifiers, in order of precedence&mdash;if you use multiple
Scott Mainbe0cf702012-01-13 11:13:13 -0800273qualifiers for a resource directory, you must add them to the directory name in the order they
Scott Main7ef674b2010-06-10 18:05:13 -0700274are listed in the table.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800275
276
Scott Main821ca512010-06-16 11:06:43 -0700277<p class="table-caption" id="table2"><strong>Table 2.</strong> Configuration qualifier
Scott Mainf940a1f2010-02-09 18:48:27 -0800278names.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700279<table>
Scott Mainf940a1f2010-02-09 18:48:27 -0800280 <tr>
Scott Mainc7eb47f2011-04-29 14:12:24 -0700281 <th>Configuration</th>
282 <th>Qualifier Values</th>
Scott Mainf940a1f2010-02-09 18:48:27 -0800283 <th>Description</th>
284 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700285 <tr id="MccQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800286 <td>MCC and MNC</td>
287 <td>Examples:<br/>
288 <code>mcc310</code><br/>
289 <code><nobr>mcc310-mnc004</nobr></code><br/>
290 <code>mcc208-mnc00</code><br/>
291 etc.
292 </td>
293 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700294 <p>The mobile country code (MCC), optionally followed by mobile network code (MNC)
295 from the SIM card in the device. For example, <code>mcc310</code> is U.S. on any carrier,
Scott Mainf940a1f2010-02-09 18:48:27 -0800296 <code>mcc310-mnc004</code> is U.S. on Verizon, and <code>mcc208-mnc00</code> is France on
297 Orange.</p>
Scott Main8edad6f2012-03-09 10:55:50 -0800298 <p>If the device uses a radio connection (GSM phone), the MCC and MNC values come
299 from the SIM card.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700300 <p>You can also use the MCC alone (for example, to include country-specific legal
301resources in your application). If you need to specify based on the language only, then use the
302<em>language and region</em> qualifier instead (discussed next). If you decide to use the MCC and
303MNC qualifier, you should do so with care and test that it works as expected.</p>
304 <p>Also see the configuration fields {@link
305android.content.res.Configuration#mcc}, and {@link
306android.content.res.Configuration#mnc}, which indicate the current mobile country code
307and mobile network code, respectively.</p>
308 </td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800309 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700310 <tr id="LocaleQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800311 <td>Language and region</td>
312 <td>Examples:<br/>
313 <code>en</code><br/>
314 <code>fr</code><br/>
315 <code>en-rUS</code><br/>
316 <code>fr-rFR</code><br/>
317 <code>fr-rCA</code><br/>
318 etc.
319 </td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700320 <td><p>The language is defined by a two-letter <a
Scott Mainf940a1f2010-02-09 18:48:27 -0800321href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
322 639-1</a> language code, optionally followed by a two letter
323 <a
324href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
Scott Mainc6cb8a72010-04-09 15:52:18 -0700325 3166-1-alpha-2</a> region code (preceded by lowercase &quot;{@code r}&quot;).
Scott Mainf940a1f2010-02-09 18:48:27 -0800326 </p><p>
327 The codes are <em>not</em> case-sensitive; the {@code r} prefix is used to
328 distinguish the region portion.
329 You cannot specify a region alone.</p>
330 <p>This can change during the life
Scott Mainc6cb8a72010-04-09 15:52:18 -0700331of your application if the user changes his or her language in the system settings. See <a
Scott Mainf940a1f2010-02-09 18:48:27 -0800332href="runtime-changes.html">Handling Runtime Changes</a> for information about
333how this can affect your application during runtime.</p>
334 <p>See <a href="localization.html">Localization</a> for a complete guide to localizing
Scott Main7ef674b2010-06-10 18:05:13 -0700335your application for other languages.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700336 <p>Also see the {@link android.content.res.Configuration#locale} configuration field, which
337indicates the current locale.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800338 </td>
339 </tr>
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700340 <tr id="LayoutDirectionQualifier">
341 <td>Layout Direction</td>
Scott Main22d17c92012-10-30 17:02:18 -0700342 <td><code>ldrtl</code><br/>
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700343 <code>ldltr</code><br/>
344 </td>
345 <td><p>The layout direction of your application. {@code ldrtl} means "layout-direction-right-to-left".
346 {@code ldltr} means "layout-direction-left-to-right" and is the default implicit value.
347 </p>
Scott Main22d17c92012-10-30 17:02:18 -0700348 <p>This can apply to any resource such as layouts, drawables, or values.
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700349 </p>
350 <p>For example, if you want to provide some specific layout for the Arabic language and some
351 generic layout for any other "right-to-left" language (like Persian or Hebrew) then you would have:
352 </p>
353<pre class="classic no-pretty-print">
354res/
355 layout/ <span style="color:black">
Scott Main22d17c92012-10-30 17:02:18 -0700356 main.xml </span>(Default layout)
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700357 layout-ar/ <span style="color:black">
Scott Main22d17c92012-10-30 17:02:18 -0700358 main.xml </span>(Specific layout for Arabic)
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700359 layout-ldrtl/ <span style="color:black">
Scott Main22d17c92012-10-30 17:02:18 -0700360 main.xml </span>(Any "right-to-left" language, except
361 for Arabic, because the "ar" language qualifier
362 has a higher precedence.)
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700363</pre>
Scott Main22d17c92012-10-30 17:02:18 -0700364 <p class="note"><strong>Note:</strong> To enable right-to-left layout features
365 for your app, you must set <a
366 href="{@docRoot}guide/topics/manifest/application-element.html#supportsrtl">{@code
367 supportsRtl}</a> to {@code "true"} and set <a
368 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target"
369 >{@code targetSdkVersion}</a> to 17 or higher.</p>
370 <p><em>Added in API level 17.</em></p>
Fabrice Di Meglio10475092012-09-06 14:06:42 -0700371 </td>
372 </tr>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700373 <tr id="SmallestScreenWidthQualifier">
Scott Main759c8932011-07-14 13:55:29 -0700374 <td>smallestWidth</td>
Scott Main9a05cfe52011-06-22 11:00:29 -0700375 <td><code>sw&lt;N&gt;dp</code><br/><br/>
376 Examples:<br/>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700377 <code>sw320dp</code><br/>
378 <code>sw600dp</code><br/>
379 <code>sw720dp</code><br/>
380 etc.
381 </td>
382 <td>
Scott Main759c8932011-07-14 13:55:29 -0700383 <p>The fundamental size of a screen, as indicated by the shortest dimension of the available
384screen area. Specifically, the device's smallestWidth is the shortest of the screen's available
385height and width (you may also think of it as the "smallest possible width" for the screen). You can
386use this qualifier to ensure that, regardless of the screen's current orientation, your
Neil Fuller71fbb812015-11-30 09:51:33 +0000387application has at least {@code <N>} dps of width available for its UI.</p>
Scott Main759c8932011-07-14 13:55:29 -0700388 <p>For example, if your layout requires that its smallest dimension of screen area be at
389least 600 dp at all times, then you can use this qualifer to create the layout resources, {@code
390res/layout-sw600dp/}. The system will use these resources only when the smallest dimension of
391available screen is at least 600dp, regardless of whether the 600dp side is the user-perceived
392height or width. The smallestWidth is a fixed screen size characteristic of the device; <strong>the
393device's smallestWidth does not change when the screen's orientation changes</strong>.</p>
394 <p>The smallestWidth of a device takes into account screen decorations and system UI. For
395example, if the device has some persistent UI elements on the screen that account for space along
396the axis of the smallestWidth, the system declares the smallestWidth to be smaller than the actual
397screen size, because those are screen pixels not available for your UI. Thus, the value you use
398should be the actual smallest dimension <em>required by your layout</em> (usually, this value is the
399"smallest width" that your layout supports, regardless of the screen's current orientation).</p>
Scott Main9a05cfe52011-06-22 11:00:29 -0700400 <p>Some values you might use here for common screen sizes:</p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700401 <ul>
Scott Main9a05cfe52011-06-22 11:00:29 -0700402 <li>320, for devices with screen configurations such as:
403 <ul>
404 <li>240x320 ldpi (QVGA handset)</li>
405 <li>320x480 mdpi (handset)</li>
Scott Rowe64f54c62014-07-23 16:10:41 -0700406 <li>480x800 hdpi (high-density handset)</li>
Scott Main9a05cfe52011-06-22 11:00:29 -0700407 </ul>
408 </li>
409 <li>480, for screens such as 480x800 mdpi (tablet/handset).</li>
410 <li>600, for screens such as 600x1024 mdpi (7" tablet).</li>
411 <li>720, for screens such as 720x1280 mdpi (10" tablet).</li>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700412 </ul>
Scott Main9a05cfe52011-06-22 11:00:29 -0700413 <p>When your application provides multiple resource directories with different values for
Scott Main759c8932011-07-14 13:55:29 -0700414 the smallestWidth qualifier, the system uses the one closest to (without exceeding) the
415device's smallestWidth. </p>
Scott Main9a05cfe52011-06-22 11:00:29 -0700416 <p><em>Added in API level 13.</em></p>
417 <p>Also see the <a
Scott Main759c8932011-07-14 13:55:29 -0700418href="{@docRoot}guide/topics/manifest/supports-screens-element.html#requiresSmallest">{@code
419android:requiresSmallestWidthDp}</a> attribute, which declares the minimum smallestWidth with which
420your application is compatible, and the {@link
421android.content.res.Configuration#smallestScreenWidthDp} configuration field, which holds the
422device's smallestWidth value.</p>
423 <p>For more information about designing for different screens and using this
424qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
425Multiple Screens</a> developer guide.</p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700426 </td>
427 </tr>
428 <tr id="ScreenWidthQualifier">
Scott Maindb909162011-06-22 14:28:44 -0700429 <td>Available width</td>
Scott Main9a05cfe52011-06-22 11:00:29 -0700430 <td><code>w&lt;N&gt;dp</code><br/><br/>
431 Examples:<br/>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700432 <code>w720dp</code><br/>
433 <code>w1024dp</code><br/>
434 etc.
435 </td>
436 <td>
Scott Maindb909162011-06-22 14:28:44 -0700437 <p>Specifies a minimum available screen width, in {@code dp} units at which the resource
Scott Main9a05cfe52011-06-22 11:00:29 -0700438 should be used&mdash;defined by the <code>&lt;N&gt;</code> value. This
439 configuration value will change when the orientation
440 changes between landscape and portrait to match the current actual width.</p>
441 <p>When your application provides multiple resource directories with different values
442 for this configuration, the system uses the one closest to (without exceeding)
443 the device's current screen width. The
444 value here takes into account screen decorations, so if the device has some
445 persistent UI elements on the left or right edge of the display, it
446 uses a value for the width that is smaller than the real screen size, accounting
447 for these UI elements and reducing the application's available space.</p>
448 <p><em>Added in API level 13.</em></p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700449 <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
450 configuration field, which holds the current screen width.</p>
Scott Main759c8932011-07-14 13:55:29 -0700451 <p>For more information about designing for different screens and using this
452qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
453Multiple Screens</a> developer guide.</p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700454 </td>
455 </tr>
456 <tr id="ScreenHeightQualifier">
Scott Maindb909162011-06-22 14:28:44 -0700457 <td>Available height</td>
Scott Main9a05cfe52011-06-22 11:00:29 -0700458 <td><code>h&lt;N&gt;dp</code><br/><br/>
459 Examples:<br/>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700460 <code>h720dp</code><br/>
461 <code>h1024dp</code><br/>
462 etc.
463 </td>
464 <td>
Scott Maindb909162011-06-22 14:28:44 -0700465 <p>Specifies a minimum available screen height, in "dp" units at which the resource
Scott Main9a05cfe52011-06-22 11:00:29 -0700466 should be used&mdash;defined by the <code>&lt;N&gt;</code> value. This
467 configuration value will change when the orientation
468 changes between landscape and portrait to match the current actual height.</p>
469 <p>When your application provides multiple resource directories with different values
470 for this configuration, the system uses the one closest to (without exceeding)
471 the device's current screen height. The
472 value here takes into account screen decorations, so if the device has some
473 persistent UI elements on the top or bottom edge of the display, it uses
474 a value for the height that is smaller than the real screen size, accounting
475 for these UI elements and reducing the application's available space. Screen
Dianne Hackbornce67da72011-06-13 22:01:13 -0700476 decorations that are not fixed (such as a phone status bar that can be
477 hidden when full screen) are <em>not</em> accounted for here, nor are
Scott Main9a05cfe52011-06-22 11:00:29 -0700478 window decorations like the title bar or action bar, so applications must be prepared to
Dianne Hackbornce67da72011-06-13 22:01:13 -0700479 deal with a somewhat smaller space than they specify.
Scott Main9a05cfe52011-06-22 11:00:29 -0700480 <p><em>Added in API level 13.</em></p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700481 <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
482 configuration field, which holds the current screen width.</p>
Scott Main759c8932011-07-14 13:55:29 -0700483 <p>For more information about designing for different screens and using this
484qualifier, see the <a href="{@docRoot}guide/practices/screens_support.html">Supporting
485Multiple Screens</a> developer guide.</p>
Dianne Hackbornce67da72011-06-13 22:01:13 -0700486 </td>
487 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700488 <tr id="ScreenSizeQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800489 <td>Screen size</td>
490 <td>
491 <code>small</code><br/>
492 <code>normal</code><br/>
Scott Mainae5335b2010-11-03 14:46:36 -0700493 <code>large</code><br/>
494 <code>xlarge</code>
Scott Mainf940a1f2010-02-09 18:48:27 -0800495 </td>
496 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700497 <ul class="nolist">
Scott Main44ec74d2011-07-12 18:10:00 -0700498 <li>{@code small}: Screens that are of similar size to a
499 low-density QVGA screen. The minimum layout size for a small screen
Scott Rowe64f54c62014-07-23 16:10:41 -0700500 is approximately 320x426 dp units. Examples are QVGA low-density and VGA high
Scott Mainf940a1f2010-02-09 18:48:27 -0800501 density.</li>
Scott Main44ec74d2011-07-12 18:10:00 -0700502 <li>{@code normal}: Screens that are of similar size to a
503 medium-density HVGA screen. The minimum
504 layout size for a normal screen is approximately 320x470 dp units. Examples
Scott Rowe64f54c62014-07-23 16:10:41 -0700505 of such screens a WQVGA low-density, HVGA medium-density, WVGA
506 high-density.</li>
Scott Main44ec74d2011-07-12 18:10:00 -0700507 <li>{@code large}: Screens that are of similar size to a
508 medium-density VGA screen.
509 The minimum layout size for a large screen is approximately 480x640 dp units.
Scott Rowe64f54c62014-07-23 16:10:41 -0700510 Examples are VGA and WVGA medium-density screens.</li>
Scott Mainae5335b2010-11-03 14:46:36 -0700511 <li>{@code xlarge}: Screens that are considerably larger than the traditional
Scott Main44ec74d2011-07-12 18:10:00 -0700512 medium-density HVGA screen. The minimum layout size for an xlarge screen
Scott Rowe64f54c62014-07-23 16:10:41 -0700513 is approximately 720x960 dp units. In most cases, devices with extra-large
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700514 screens would be too large to carry in a pocket and would most likely
Scott Main9a05cfe52011-06-22 11:00:29 -0700515 be tablet-style devices. <em>Added in API level 9.</em></li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800516 </ul>
Scott Main44ec74d2011-07-12 18:10:00 -0700517 <p class="note"><strong>Note:</strong> Using a size qualifier does not imply that the
518resources are <em>only</em> for screens of that size. If you do not provide alternative
519resources with qualifiers that better match the current device configuration, the system may use
520whichever resources are the <a href="#BestMatch">best match</a>.</p>
521 <p class="caution"><strong>Caution:</strong> If all your resources use a size qualifier that
522is <em>larger</em> than the current screen, the system will <strong>not</strong> use them and your
523application will crash at runtime (for example, if all layout resources are tagged with the {@code
524xlarge} qualifier, but the device is a normal-size screen).</p>
Scott Main9a05cfe52011-06-22 11:00:29 -0700525 <p><em>Added in API level 4.</em></p>
Mark Luc4a01392016-07-18 10:42:11 -0700526
Scott Mainf940a1f2010-02-09 18:48:27 -0800527 <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
528Screens</a> for more information.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700529 <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
530which indicates whether the screen is small, normal,
531or large.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800532 </td>
533 </tr>
Scott Main821ca512010-06-16 11:06:43 -0700534 <tr id="ScreenAspectQualifier">
535 <td>Screen aspect</td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800536 <td>
537 <code>long</code><br/>
538 <code>notlong</code>
539 </td>
540 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700541 <ul class="nolist">
542 <li>{@code long}: Long screens, such as WQVGA, WVGA, FWVGA</li>
543 <li>{@code notlong}: Not long screens, such as QVGA, HVGA, and VGA</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800544 </ul>
Scott Main9a05cfe52011-06-22 11:00:29 -0700545 <p><em>Added in API level 4.</em></p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700546 <p>This is based purely on the aspect ratio of the screen (a "long" screen is wider). This
547is not related to the screen orientation.</p>
548 <p>Also see the {@link android.content.res.Configuration#screenLayout} configuration field,
549which indicates whether the screen is long.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800550 </td>
551 </tr>
Adam Lesinskif1780662015-06-30 11:49:41 -0700552 <tr id="ScreenRoundQualifier">
553 <td>Round screen</td>
554 <td>
555 <code>round</code><br/>
556 <code>notround</code>
557 </td>
558 <td>
559 <ul class="nolist">
560 <li>{@code round}: Round screens, such as a round wearable device</li>
561 <li>{@code notround}: Rectangular screens, such as phones or tablets</li>
562 </ul>
563 <p><em>Added in API level 23.</em></p>
564 <p>Also see the {@link android.content.res.Configuration#isScreenRound()} configuration
565method, which indicates whether the screen is round.</p>
566 </td>
567 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700568 <tr id="OrientationQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800569 <td>Screen orientation</td>
570 <td>
571 <code>port</code><br/>
572 <code>land</code> <!-- <br/>
573 <code>square</code> -->
574 </td>
575 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700576 <ul class="nolist">
577 <li>{@code port}: Device is in portrait orientation (vertical)</li>
578 <li>{@code land}: Device is in landscape orientation (horizontal)</li>
579 <!-- Square mode is currently not used. -->
580 </ul>
Scott Mainf940a1f2010-02-09 18:48:27 -0800581 <p>This can change during the life of your application if the user rotates the
582screen. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about
583how this affects your application during runtime.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700584 <p>Also see the {@link android.content.res.Configuration#orientation} configuration field,
585which indicates the current device orientation.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800586 </td>
587 </tr>
Dianne Hackborne302a162012-05-15 14:58:32 -0700588 <tr id="UiModeQualifier">
589 <td>UI mode</td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800590 <td>
591 <code>car</code><br/>
Dianne Hackborne302a162012-05-15 14:58:32 -0700592 <code>desk</code><br/>
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700593 <code>television<br/>
594 <code>appliance</code>
John Spurlock6c191292014-04-03 16:37:27 -0400595 <code>watch</code>
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800596 <code>vrheadset</code>
Scott Mainf940a1f2010-02-09 18:48:27 -0800597 </td>
598 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700599 <ul class="nolist">
Dianne Hackborne302a162012-05-15 14:58:32 -0700600 <li>{@code car}: Device is displaying in a car dock</li>
601 <li>{@code desk}: Device is displaying in a desk dock</li>
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700602 <li>{@code television}: Device is displaying on a television, providing
603 a "ten foot" experience where its UI is on a large screen that the
604 user is far away from, primarily oriented around DPAD or other
605 non-pointer interaction</li>
606 <li>{@code appliance}: Device is serving as an appliance, with
607 no display</li>
John Spurlock6c191292014-04-03 16:37:27 -0400608 <li>{@code watch}: Device has a display and is worn on the wrist</li>
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800609 <li>{@code vrheadset}: Device has a virtual reality capable display and is showing the the apps UI on a virtual display</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700610 </ul>
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800611 <p><em>Added in API level 8, television added in API 13, watch added in API 20, vrheadset added in API 26.</em></p>
Scott Mainc73d67f2012-09-10 16:20:08 -0700612 <p>For information about how your app can respond when the device is inserted into or
Mark Luc4a01392016-07-18 10:42:11 -0700613 removed from a dock, read <a
Scott Mainc73d67f2012-09-10 16:20:08 -0700614 href="{@docRoot}training/monitoring-device-state/docking-monitoring.html">Determining
615and Monitoring the Docking State and Type</a>.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800616 <p>This can change during the life of your application if the user places the device in a
Dianne Hackborne302a162012-05-15 14:58:32 -0700617dock. You can enable or disable some of these modes using {@link
Scott Mainc6cb8a72010-04-09 15:52:18 -0700618android.app.UiModeManager}. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
619information about how this affects your application during runtime.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800620 </td>
621 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700622 <tr id="NightQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800623 <td>Night mode</td>
624 <td>
625 <code>night</code><br/>
626 <code>notnight</code>
627 </td>
628 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700629 <ul class="nolist">
630 <li>{@code night}: Night time</li>
631 <li>{@code notnight}: Day time</li>
632 </ul>
Scott Main9a05cfe52011-06-22 11:00:29 -0700633 <p><em>Added in API level 8.</em></p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700634 <p>This can change during the life of your application if night mode is left in
Scott Main7ef674b2010-06-10 18:05:13 -0700635auto mode (default), in which case the mode changes based on the time of day. You can enable
Scott Mainc6cb8a72010-04-09 15:52:18 -0700636or disable this mode using {@link android.app.UiModeManager}. See <a
637href="runtime-changes.html">Handling Runtime Changes</a> for information about how this affects your
638application during runtime.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800639 </td>
640 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700641 <tr id="DensityQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800642 <td>Screen pixel density (dpi)</td>
643 <td>
644 <code>ldpi</code><br/>
645 <code>mdpi</code><br/>
646 <code>hdpi</code><br/>
Scott Mainae5335b2010-11-03 14:46:36 -0700647 <code>xhdpi</code><br/>
Scott Rowe64f54c62014-07-23 16:10:41 -0700648 <code>xxhdpi</code><br/>
649 <code>xxxhdpi</code><br/>
Scott Main44ec74d2011-07-12 18:10:00 -0700650 <code>nodpi</code><br/>
Adam Lesinski4cad00b2015-09-08 14:16:49 -0700651 <code>tvdpi</code><br/>
652 <code>anydpi</code>
Scott Mainf940a1f2010-02-09 18:48:27 -0800653 </td>
654 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700655 <ul class="nolist">
656 <li>{@code ldpi}: Low-density screens; approximately 120dpi.</li>
657 <li>{@code mdpi}: Medium-density (on traditional HVGA) screens; approximately
658160dpi.</li>
659 <li>{@code hdpi}: High-density screens; approximately 240dpi.</li>
Scott Rowe64f54c62014-07-23 16:10:41 -0700660 <li>{@code xhdpi}: Extra-high-density screens; approximately 320dpi. <em>Added in API
Scott Mainae5335b2010-11-03 14:46:36 -0700661Level 8</em></li>
Scott Rowe64f54c62014-07-23 16:10:41 -0700662 <li>{@code xxhdpi}: Extra-extra-high-density screens; approximately 480dpi. <em>Added in API
663Level 16</em></li>
Mark Luc4a01392016-07-18 10:42:11 -0700664 <li>{@code xxxhdpi}: Extra-extra-extra-high-density uses (launcher icon only, see the
665 <a href="{@docRoot}guide/practices/screens_support.html#xxxhdpi-note">note</a>
Scott Rowe64f54c62014-07-23 16:10:41 -0700666 in <em>Supporting Multiple Screens</em>); approximately 640dpi. <em>Added in API
667Level 18</em></li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700668 <li>{@code nodpi}: This can be used for bitmap resources that you do not want to be scaled
669to match the device density.</li>
Scott Main44ec74d2011-07-12 18:10:00 -0700670 <li>{@code tvdpi}: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is
671not considered a "primary" density group. It is mostly intended for televisions and most
672apps shouldn't need it&mdash;providing mdpi and hdpi resources is sufficient for most apps and
Adam Lesinski4cad00b2015-09-08 14:16:49 -0700673the system will scale them as appropriate. <em>Added in API Level 13</em></li>
674 <li>{@code anydpi}: This qualifier matches all screen densities and takes precedence over
675other qualifiers. This is useful for
676<a href="{@docRoot}training/material/drawables.html#VectorDrawables">vector drawables</a>.
677<em>Added in API Level 21</em></li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700678 </ul>
Scott Rowe64f54c62014-07-23 16:10:41 -0700679 <p>There is a 3:4:6:8:12:16 scaling ratio between the six primary densities (ignoring the
680tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi, 24x24 in xhdpi and so on.
681</p>
Scott Main44ec74d2011-07-12 18:10:00 -0700682 <p>If you decide that your image resources don't look good enough on a television or
683other certain devices and want to try tvdpi resources, the scaling factor is 1.33*mdpi. For
684example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.</p>
685 <p class="note"><strong>Note:</strong> Using a density qualifier does not imply that the
686resources are <em>only</em> for screens of that density. If you do not provide alternative
687resources with qualifiers that better match the current device configuration, the system may use
688whichever resources are the <a href="#BestMatch">best match</a>.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800689 <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
Scott Main44ec74d2011-07-12 18:10:00 -0700690Screens</a> for more information about how to handle different screen densities and how Android
691might scale your bitmaps to fit the current density.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800692 </td>
693 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700694 <tr id="TouchscreenQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800695 <td>Touchscreen type</td>
696 <td>
697 <code>notouch</code><br/>
Scott Mainf940a1f2010-02-09 18:48:27 -0800698 <code>finger</code>
699 </td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700700 <td>
701 <ul class="nolist">
702 <li>{@code notouch}: Device does not have a touchscreen.</li>
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700703 <li>{@code finger}: Device has a touchscreen that is intended to
704 be used through direction interaction of the user's finger.</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700705 </ul>
706 <p>Also see the {@link android.content.res.Configuration#touchscreen} configuration field,
707which indicates the type of touchscreen on the device.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800708 </td>
709 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700710 <tr id="KeyboardAvailQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800711 <td>Keyboard availability</td>
712 <td>
713 <code>keysexposed</code><br/>
Keiji Ariyamaa84e0882011-01-22 01:58:25 +0900714 <code>keyshidden</code><br/>
Scott Mainf940a1f2010-02-09 18:48:27 -0800715 <code>keyssoft</code>
716 </td>
717 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700718 <ul class="nolist">
719 <li>{@code keysexposed}: Device has a keyboard available. If the device has a
720software keyboard enabled (which is likely), this may be used even when the hardware keyboard is
721<em>not</em> exposed to the user, even if the device has no hardware keyboard. If no software
722keyboard is provided or it's disabled, then this is only used when a hardware keyboard is
723exposed.</li>
724 <li>{@code keyshidden}: Device has a hardware keyboard available but it is
725hidden <em>and</em> the device does <em>not</em> have a software keyboard enabled.</li>
726 <li>{@code keyssoft}: Device has a software keyboard enabled, whether it's
727visible or not.</li>
728 </ul>
729 <p>If you provide <code>keysexposed</code> resources, but not <code>keyssoft</code>
730resources, the system uses the <code>keysexposed</code> resources regardless of whether a
731keyboard is visible, as long as the system has a software keyboard enabled.</p>
732 <p>This can change during the life of your application if the user opens a hardware
733keyboard. See <a href="runtime-changes.html">Handling Runtime Changes</a> for information about how
734this affects your application during runtime.</p>
735 <p>Also see the configuration fields {@link
736android.content.res.Configuration#hardKeyboardHidden} and {@link
737android.content.res.Configuration#keyboardHidden}, which indicate the visibility of a hardware
738keyboard and and the visibility of any kind of keyboard (including software), respectively.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800739 </td>
740 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700741 <tr id="ImeQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800742 <td>Primary text input method</td>
743 <td>
744 <code>nokeys</code><br/>
745 <code>qwerty</code><br/>
746 <code>12key</code>
747 </td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700748 <td>
749 <ul class="nolist">
750 <li>{@code nokeys}: Device has no hardware keys for text input.</li>
Scott Main7ef674b2010-06-10 18:05:13 -0700751 <li>{@code qwerty}: Device has a hardware qwerty keyboard, whether it's visible to the
752user
Scott Mainc6cb8a72010-04-09 15:52:18 -0700753or not.</li>
754 <li>{@code 12key}: Device has a hardware 12-key keyboard, whether it's visible to the user
755or not.</li>
756 </ul>
757 <p>Also see the {@link android.content.res.Configuration#keyboard} configuration field,
758which indicates the primary text input method available.</p>
759 </td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800760 </tr>
Scott Main7ef674b2010-06-10 18:05:13 -0700761 <tr id="NavAvailQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800762 <td>Navigation key availability</td>
763 <td>
764 <code>navexposed</code><br/>
765 <code>navhidden</code>
766 </td>
767 <td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700768 <ul class="nolist">
769 <li>{@code navexposed}: Navigation keys are available to the user.</li>
770 <li>{@code navhidden}: Navigation keys are not available (such as behind a closed
771lid).</li>
772 </ul>
Scott Mainf940a1f2010-02-09 18:48:27 -0800773 <p>This can change during the life of your application if the user reveals the navigation
774keys. See <a href="runtime-changes.html">Handling Runtime Changes</a> for
775information about how this affects your application during runtime.</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700776 <p>Also see the {@link android.content.res.Configuration#navigationHidden} configuration
777field, which indicates whether navigation keys are hidden.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800778 </td>
779 </tr>
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700780 <tr id="NavigationQualifier">
Scott Mainf940a1f2010-02-09 18:48:27 -0800781 <td>Primary non-touch navigation method</td>
782 <td>
783 <code>nonav</code><br/>
784 <code>dpad</code><br/>
785 <code>trackball</code><br/>
786 <code>wheel</code>
787 </td>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700788 <td>
789 <ul class="nolist">
790 <li>{@code nonav}: Device has no navigation facility other than using the
791touchscreen.</li>
792 <li>{@code dpad}: Device has a directional-pad (d-pad) for navigation.</li>
793 <li>{@code trackball}: Device has a trackball for navigation.</li>
794 <li>{@code wheel}: Device has a directional wheel(s) for navigation (uncommon).</li>
795 </ul>
796 <p>Also see the {@link android.content.res.Configuration#navigation} configuration field,
797which indicates the type of navigation method available.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800798 </td>
799 </tr>
800<!-- DEPRECATED
801 <tr>
802 <td>Screen dimensions</td>
803 <td>Examples:<br/>
804 <code>320x240</code><br/>
805 <code>640x480</code><br/>
806 etc.
807 </td>
808 <td>
809 <p>The larger dimension must be specified first. <strong>This configuration is deprecated
810and should not be used</strong>. Instead use "screen size," "wider/taller screens," and "screen
811orientation" described above.</p>
812 </td>
813 </tr>
814-->
Scott Main7ef674b2010-06-10 18:05:13 -0700815 <tr id="VersionQualifier">
Scott Main9a05cfe52011-06-22 11:00:29 -0700816 <td>Platform Version (API level)</td>
Scott Mainf940a1f2010-02-09 18:48:27 -0800817 <td>Examples:<br/>
Scott Main7ef674b2010-06-10 18:05:13 -0700818 <code>v3</code><br/>
Scott Mainf940a1f2010-02-09 18:48:27 -0800819 <code>v4</code><br/>
Scott Mainf940a1f2010-02-09 18:48:27 -0800820 <code>v7</code><br/>
821 etc.</td>
822 <td>
Scott Main9a05cfe52011-06-22 11:00:29 -0700823 <p>The API level supported by the device. For example, <code>v1</code> for API level
8241 (devices with Android 1.0 or higher) and <code>v4</code> for API level 4 (devices with Android
Scott Main7ef674b2010-06-10 18:05:13 -07008251.6 or higher). See the <a
Scott Main50e990c2012-06-21 17:14:39 -0700826href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">Android API levels</a> document for more information
Scott Mainf940a1f2010-02-09 18:48:27 -0800827about these values.</p>
828 </td>
829 </tr>
830</table>
831
Scott Mainc6cb8a72010-04-09 15:52:18 -0700832
Scott Mainbe0cf702012-01-13 11:13:13 -0800833<p class="note"><strong>Note:</strong> Some configuration qualifiers have been added since Android
8341.0, so not all versions of Android support all the qualifiers. Using a new qualifier implicitly
835adds the platform version qualifier so that older devices are sure to ignore it. For example, using
836a <code>w600dp</code> qualifier will automatically include the <code>v13</code> qualifier, because
837the available-width qualifier was new in API level 13. To avoid any issues, always include a set of
838default resources (a set of resources with <em>no qualifiers</em>). For more information, see the
839section about <a href="#Compatibility">Providing the Best Device Compatibility with
840Resources</a>.</p>
841
842
843
Scott Mainc6cb8a72010-04-09 15:52:18 -0700844<h3 id="QualifierRules">Qualifier name rules</h3>
845
Scott Main821ca512010-06-16 11:06:43 -0700846<p>Here are some rules about using configuration qualifier names:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800847
848<ul>
849 <li>You can specify multiple qualifiers for a single set of resources, separated by dashes. For
850example, <code>drawable-en-rUS-land</code> applies to US-English devices in landscape
851orientation.</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700852 <li>The qualifiers must be in the order listed in <a href="#table2">table 2</a>. For
Scott Mainf940a1f2010-02-09 18:48:27 -0800853example:
854 <ul>
855 <li>Wrong: <code>drawable-hdpi-port/</code></li>
856 <li>Correct: <code>drawable-port-hdpi/</code></li>
857 </ul>
858 </li>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700859 <li>Alternative resource directories cannot be nested. For example, you cannot have
Scott Mainf940a1f2010-02-09 18:48:27 -0800860<code>res/drawable/drawable-en/</code>.</li>
861 <li>Values are case-insensitive. The resource compiler converts directory names
862 to lower case before processing to avoid problems on case-insensitive
863 file systems. Any capitalization in the names is only to benefit readability.</li>
864 <li>Only one value for each qualifier type is supported. For example, if you want to use
865the same drawable files for Spain and France, you <em>cannot</em> have a directory named
866<code>drawable-rES-rFR/</code>. Instead you need two resource directories, such as
867<code>drawable-rES/</code> and <code>drawable-rFR/</code>, which contain the appropriate files.
Scott Mainc6cb8a72010-04-09 15:52:18 -0700868However, you are not required to actually duplicate the same files in both locations. Instead, you
869can create an alias to a resource. See <a href="#AliasResources">Creating
870alias resources</a> below.</li>
Scott Mainf940a1f2010-02-09 18:48:27 -0800871</ul>
872
Scott Mainc6cb8a72010-04-09 15:52:18 -0700873<p>After you save alternative resources into directories named with
874these qualifiers, Android automatically applies the resources in your application based on the
875current device configuration. Each time a resource is requested, Android checks for alternative
876resource directories that contain the requested resource file, then <a href="#BestMatch">finds the
Scott Main821ca512010-06-16 11:06:43 -0700877best-matching resource</a> (discussed below). If there are no alternative resources that match
878a particular device configuration, then Android uses the corresponding default resources (the
879set of resources for a particular resource type that does not include a configuration
880qualifier).</p>
Scott Mainc6cb8a72010-04-09 15:52:18 -0700881
Scott Mainf940a1f2010-02-09 18:48:27 -0800882
883
884<h3 id="AliasResources">Creating alias resources</h3>
885
886<p>When you have a resource that you'd like to use for more than one device
Scott Main821ca512010-06-16 11:06:43 -0700887configuration (but do not want to provide as a default resource), you do not need to put the same
888resource in more than one alternative resource directory. Instead, you can (in some cases) create an
889alternative
Scott Mainf940a1f2010-02-09 18:48:27 -0800890resource that acts as an alias for a resource saved in your default resource directory.</p>
891
Scott Mainc6cb8a72010-04-09 15:52:18 -0700892<p class="note"><strong>Note:</strong> Not all resources offer a mechanism by which you can
893create an alias to another resource. In particular, animation, menu, raw, and other unspecified
894resources in the {@code xml/} directory do not offer this feature.</p>
895
896<p>For example, imagine you have an application icon, {@code icon.png}, and need unique version of
897it for different locales. However, two locales, English-Canadian and French-Canadian, need to
898use the same version. You might assume that you need to copy the same image
899into the resource directory for both English-Canadian and French-Canadian, but it's
900not true. Instead, you can save the image that's used for both as {@code icon_ca.png} (any
901name other than {@code icon.png}) and put
Scott Mainf940a1f2010-02-09 18:48:27 -0800902it in the default {@code res/drawable/} directory. Then create an {@code icon.xml} file in {@code
903res/drawable-en-rCA/} and {@code res/drawable-fr-rCA/} that refers to the {@code icon_ca.png}
Neil Fuller71fbb812015-11-30 09:51:33 +0000904resource using the {@code <bitmap>} element. This allows you to store just one version of the
Scott Mainf940a1f2010-02-09 18:48:27 -0800905PNG file and two small XML files that point to it. (An example XML file is shown below.)</p>
906
Scott Mainf940a1f2010-02-09 18:48:27 -0800907
908<h4>Drawable</h4>
909
Hemal Patelad302b62016-10-03 18:27:18 -0700910<p>
911 To create an alias to an existing drawable, use the {@code <drawable>}
912 element. For example:
913</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800914
915<pre>
916&lt;?xml version="1.0" encoding="utf-8"?>
Hemal Patelad302b62016-10-03 18:27:18 -0700917&lt;resources&gt;
918 &lt;drawable name="icon"&gt;&#64;drawable/icon_ca&lt;/drawable&gt;
919&lt;/resources&gt;
Scott Mainf940a1f2010-02-09 18:48:27 -0800920</pre>
921
Hemal Patelad302b62016-10-03 18:27:18 -0700922<p>
923 If you save this file as {@code drawables.xml} (in an alternative resource
924 directory, such as {@code res/values-en-rCA/}), it is compiled into a
925 resource that you can reference as {@code R.drawable.icon}, but is actually
926 an alias for the {@code R.drawable.icon_ca} resource (which is saved in
927 {@code res/drawable/}).
928</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800929
930<h4>Layout</h4>
931
Neil Fuller71fbb812015-11-30 09:51:33 +0000932<p>To create an alias to an existing layout, use the {@code <include>}
933element, wrapped in a {@code <merge>}. For example:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -0800934
935<pre>
936&lt;?xml version="1.0" encoding="utf-8"?>
937&lt;merge>
938 &lt;include layout="@layout/main_ltr"/>
939&lt;/merge>
940</pre>
941
Scott Mainc6cb8a72010-04-09 15:52:18 -0700942<p>If you save this file as {@code main.xml}, it is compiled into a resource you can reference
Scott Mainf940a1f2010-02-09 18:48:27 -0800943as {@code R.layout.main}, but is actually an alias for the {@code R.layout.main_ltr}
944resource.</p>
945
946
947<h4>Strings and other simple values</h4>
948
949<p>To create an alias to an existing string, simply use the resource ID of the desired
950string as the value for the new string. For example:</p>
951
952<pre>
953&lt;?xml version="1.0" encoding="utf-8"?>
954&lt;resources>
955 &lt;string name="hello">Hello&lt;/string>
956 &lt;string name="hi">@string/hello&lt;/string>
957&lt;/resources>
958</pre>
959
960<p>The {@code R.string.hi} resource is now an alias for the {@code R.string.hello}.</p>
961
962<p> <a href="{@docRoot}guide/topics/resources/more-resources.html">Other simple values</a> work the
963same way. For example, a color:</p>
964
965<pre>
966&lt;?xml version="1.0" encoding="utf-8"?>
967&lt;resources>
Chris Craik5d8b2df2015-07-16 13:44:26 -0700968 &lt;color name="red">#f00&lt;/color>
Scott Mainf940a1f2010-02-09 18:48:27 -0800969 &lt;color name="highlight">@color/red&lt;/color>
970&lt;/resources>
971</pre>
972
973
974
975
Scott Main7ef674b2010-06-10 18:05:13 -0700976<h2 id="Compatibility">Providing the Best Device Compatibility with Resources</h2>
977
978<p>In order for your application to support multiple device configurations, it's very important that
979you always provide default resources for each type of resource that your application uses.</p>
980
981<p>For example, if your application supports several languages, always include a {@code
982values/} directory (in which your strings are saved) <em>without</em> a <a
Scott Main369c1c12010-12-07 11:17:00 -0800983href="#LocaleQualifier">language and region qualifier</a>. If you instead put all your string files
Scott Main7ef674b2010-06-10 18:05:13 -0700984in directories that have a language and region qualifier, then your application will crash when run
985on a device set to a language that your strings do not support. But, as long as you provide default
986{@code values/} resources, then your application will run properly (even if the user doesn't
987understand that language&mdash;it's better than crashing).</p>
988
989<p>Likewise, if you provide different layout resources based on the screen orientation, you should
990pick one orientation as your default. For example, instead of providing layout resources in {@code
991layout-land/} for landscape and {@code layout-port/} for portrait, leave one as the default, such as
992{@code layout/} for landscape and {@code layout-port/} for portrait.</p>
993
994<p>Providing default resources is important not only because your application might run on a
995configuration you had not anticipated, but also because new versions of Android sometimes add
Scott Main821ca512010-06-16 11:06:43 -0700996configuration qualifiers that older versions do not support. If you use a new resource qualifier,
Scott Main7ef674b2010-06-10 18:05:13 -0700997but maintain code compatibility with older versions of Android, then when an older version of
998Android runs your application, it will crash if you do not provide default resources, because it
999cannot use the resources named with the new qualifier. For example, if your <a
1000href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
1001minSdkVersion}</a> is set to 4, and you qualify all of your drawable resources using <a
Scott Main1c8b6ca2010-07-02 11:11:34 -07001002href="#NightQualifier">night mode</a> ({@code night} or {@code notnight}, which were added in API
Scott Main9a05cfe52011-06-22 11:00:29 -07001003Level 8), then an API level 4 device cannot access your drawable resources and will crash. In this
Scott Main7ef674b2010-06-10 18:05:13 -07001004case, you probably want {@code notnight} to be your default resources, so you should exclude that
1005qualifier so your drawable resources are in either {@code drawable/} or {@code drawable-night/}.</p>
1006
Scott Main821ca512010-06-16 11:06:43 -07001007<p>So, in order to provide the best device compatibility, always provide default
1008resources for the resources your application needs to perform properly. Then create alternative
1009resources for specific device configurations using the configuration qualifiers.</p>
Scott Main7ef674b2010-06-10 18:05:13 -07001010
1011<p>There is one exception to this rule: If your application's <a
1012href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> is 4 or
1013greater, you <em>do not</em> need default drawable resources when you provide alternative drawable
1014resources with the <a href="#DensityQualifier">screen density</a> qualifier. Even without default
1015drawable resources, Android can find the best match among the alternative screen densities and scale
1016the bitmaps as necessary. However, for the best experience on all types of devices, you should
Scott Mainc8931202013-05-06 16:38:42 -07001017provide alternative drawables for all three types of density.</p>
Scott Main821ca512010-06-16 11:06:43 -07001018
Scott Main7ef674b2010-06-10 18:05:13 -07001019
Scott Mainf940a1f2010-02-09 18:48:27 -08001020
1021<h2 id="BestMatch">How Android Finds the Best-matching Resource</h2>
1022
Scott Mainc6cb8a72010-04-09 15:52:18 -07001023<p>When you request a resource for which you provide alternatives, Android selects which
1024alternative resource to use at runtime, depending on the current device configuration. To
1025demonstrate how Android selects an alternative resource, assume the following drawable directories
1026each contain different versions of the same images:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -08001027
Scott Mainc6cb8a72010-04-09 15:52:18 -07001028<pre class="classic no-pretty-print">
1029drawable/
1030drawable-en/
1031drawable-fr-rCA/
1032drawable-en-port/
1033drawable-en-notouch-12key/
1034drawable-port-ldpi/
1035drawable-port-notouch-12key/
Scott Mainf940a1f2010-02-09 18:48:27 -08001036</pre>
1037
1038<p>And assume the following is the device configuration:</p>
1039
Scott Mainc6cb8a72010-04-09 15:52:18 -07001040<p style="margin-left:1em;">
Scott Mainf940a1f2010-02-09 18:48:27 -08001041Locale = <code>en-GB</code> <br/>
1042Screen orientation = <code>port</code> <br/>
1043Screen pixel density = <code>hdpi</code> <br/>
1044Touchscreen type = <code>notouch</code> <br/>
1045Primary text input method = <code>12key</code>
1046</p>
1047
Scott Mainc6cb8a72010-04-09 15:52:18 -07001048<p>By comparing the device configuration to the available alternative resources, Android selects
Scott Main44ec74d2011-07-12 18:10:00 -07001049drawables from {@code drawable-en-port}.</p>
1050
1051<p>The system arrives at its decision for which resources to use with the following
1052logic:</p>
Scott Mainf940a1f2010-02-09 18:48:27 -08001053
Scott Mainc6cb8a72010-04-09 15:52:18 -07001054
Scott Maine63163a2012-01-03 10:10:21 -08001055<div class="figure" style="width:371px">
1056<img src="{@docRoot}images/resources/res-selection-flowchart.png" alt="" height="471" />
Scott Mainc6cb8a72010-04-09 15:52:18 -07001057<p class="img-caption"><strong>Figure 2.</strong> Flowchart of how Android finds the
1058best-matching resource.</p>
1059</div>
1060
Scott Mainf940a1f2010-02-09 18:48:27 -08001061
1062<ol>
1063 <li>Eliminate resource files that contradict the device configuration.
Scott Mainc6cb8a72010-04-09 15:52:18 -07001064 <p>The <code>drawable-fr-rCA/</code> directory is eliminated, because it
1065contradicts the <code>en-GB</code> locale.</p>
1066<pre class="classic no-pretty-print">
Scott Mainf940a1f2010-02-09 18:48:27 -08001067drawable/
1068drawable-en/
1069<strike>drawable-fr-rCA/</strike>
1070drawable-en-port/
1071drawable-en-notouch-12key/
1072drawable-port-ldpi/
Scott Mainc6cb8a72010-04-09 15:52:18 -07001073drawable-port-notouch-12key/
Scott Mainf940a1f2010-02-09 18:48:27 -08001074</pre>
Scott Mainc6cb8a72010-04-09 15:52:18 -07001075<p class="note"><strong>Exception:</strong> Screen pixel density is the one qualifier that is not
Gilles Debunnec09a6972010-07-28 09:01:34 -07001076eliminated due to a contradiction. Even though the screen density of the device is hdpi,
Scott Mainf940a1f2010-02-09 18:48:27 -08001077<code>drawable-port-ldpi/</code> is not eliminated because every screen density is
Scott Mainc6cb8a72010-04-09 15:52:18 -07001078considered to be a match at this point. More information is available in the <a
1079href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1080Screens</a> document.</p></li>
Scott Mainf940a1f2010-02-09 18:48:27 -08001081
Scott Mainc6cb8a72010-04-09 15:52:18 -07001082 <li>Pick the (next) highest-precedence qualifier in the list (<a href="#table2">table 2</a>).
1083(Start with MCC, then move down.) </li>
1084 <li>Do any of the resource directories include this qualifier? </li>
Scott Mainf940a1f2010-02-09 18:48:27 -08001085 <ul>
Scott Mainc6cb8a72010-04-09 15:52:18 -07001086 <li>If No, return to step 2 and look at the next qualifier. (In the example,
1087 the answer is &quot;no&quot; until the language qualifier is reached.)</li>
1088 <li>If Yes, continue to step 4.</li>
Scott Mainf940a1f2010-02-09 18:48:27 -08001089 </ul>
1090 </li>
1091
1092 <li>Eliminate resource directories that do not include this qualifier. In the example, the system
1093eliminates all the directories that do not include a language qualifier:</li>
Scott Mainc6cb8a72010-04-09 15:52:18 -07001094<pre class="classic no-pretty-print">
Scott Mainf940a1f2010-02-09 18:48:27 -08001095<strike>drawable/</strike>
1096drawable-en/
1097drawable-en-port/
1098drawable-en-notouch-12key/
1099<strike>drawable-port-ldpi/</strike>
Scott Mainc6cb8a72010-04-09 15:52:18 -07001100<strike>drawable-port-notouch-12key/</strike>
Scott Mainf940a1f2010-02-09 18:48:27 -08001101</pre>
1102<p class="note"><strong>Exception:</strong> If the qualifier in question is screen pixel density,
Gilles Debunnec09a6972010-07-28 09:01:34 -07001103Android selects the option that most closely matches the device screen density.
1104In general, Android prefers scaling down a larger original image to scaling up a smaller
Scott Mainc6cb8a72010-04-09 15:52:18 -07001105original image. See <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1106Screens</a>.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -08001107 </li>
1108
Scott Mainc6cb8a72010-04-09 15:52:18 -07001109 <li>Go back and repeat steps 2, 3, and 4 until only one directory remains. In the example, screen
Scott Mainf940a1f2010-02-09 18:48:27 -08001110orientation is the next qualifier for which there are any matches.
1111So, resources that do not specify a screen orientation are eliminated:
Scott Mainc6cb8a72010-04-09 15:52:18 -07001112<pre class="classic no-pretty-print">
Scott Mainf940a1f2010-02-09 18:48:27 -08001113<strike>drawable-en/</strike>
1114drawable-en-port/
1115<strike>drawable-en-notouch-12key/</strike>
1116</pre>
Scott Mainc6cb8a72010-04-09 15:52:18 -07001117<p>The remaining directory is {@code drawable-en-port}.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -08001118 </li>
1119</ol>
1120
Scott Mainc6cb8a72010-04-09 15:52:18 -07001121<p>Though this procedure is executed for each resource requested, the system further optimizes
Scott Mainf940a1f2010-02-09 18:48:27 -08001122some aspects. One such optimization is that once the device configuration is known, it might
Scott Mainc6cb8a72010-04-09 15:52:18 -07001123eliminate alternative resources that can never match. For example, if the configuration
Scott Mainf940a1f2010-02-09 18:48:27 -08001124language is English ("en"), then any resource directory that has a language qualifier set to
Scott Mainc6cb8a72010-04-09 15:52:18 -07001125something other than English is never included in the pool of resources checked (though a
Scott Mainf940a1f2010-02-09 18:48:27 -08001126resource directory <em>without</em> the language qualifier is still included).</p>
1127
Scott Main44ec74d2011-07-12 18:10:00 -07001128<p>When selecting resources based on the screen size qualifiers, the system will use resources
1129designed for a screen smaller than the current screen if there are no resources that better match
1130(for example, a large-size screen will use normal-size screen resources if necessary). However, if
1131the only available resources are <em>larger</em> than the current screen, the system will
1132<strong>not</strong> use them and your application will crash if no other resources match the device
1133configuration (for example, if all layout resources are tagged with the {@code xlarge} qualifier,
1134but the device is a normal-size screen).</p>
1135
Scott Mainf940a1f2010-02-09 18:48:27 -08001136<p class="note"><strong>Note:</strong> The <em>precedence</em> of the qualifier (in <a
Scott Mainc6cb8a72010-04-09 15:52:18 -07001137href="#table2">table 2</a>) is more important
Scott Mainf940a1f2010-02-09 18:48:27 -08001138than the number of qualifiers that exactly match the device. For example, in step 4 above, the last
1139choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen
1140type, and input method), while <code>drawable-en</code> has only one parameter that matches
1141(language). However, language has a higher precedence than these other qualifiers, so
Scott Mainc6cb8a72010-04-09 15:52:18 -07001142<code>drawable-port-notouch-12key</code> is out.</p>
Scott Mainf940a1f2010-02-09 18:48:27 -08001143
Scott Mainc6cb8a72010-04-09 15:52:18 -07001144<p>To learn more about how to use resources in your application, continue to <a
1145href="accessing-resources.html">Accessing Resources</a>.</p>