index.jd revision c6cb8a78d03cda44a49a990b4d4153560bee7420
1page.title=Application Resources
2@jd:body
3
4<div id="qv-wrapper">
5<div id="qv">
6  <h2>Topics</h2>
7  <ol>
8    <li><a href="providing-resources.html">Providing Resources</a></li>
9    <li><a href="accessing-resources.html">Accessing Resources</a></li>
10    <li><a href="runtime-changes.html">Handling Runtime Changes</a></li>
11    <li><a href="localization.html">Localization</a></li>
12  </ol>
13
14  <h2>Reference</h2>
15  <ol>
16    <li><a href="available-resources.html">Resource Types</a></li>
17  </ol>
18</div>
19</div>
20
21
22<p>You should always externalize resources such as images and strings from your application
23code, so that you can maintain them independently. Externalizing your
24resources also allows you to provide alternative resources that support specific device
25configurations such as different languages or screen sizes, which becomes increasingly
26important as more Android-powered devices become available with different configurations. In order
27to provide this functionality, you must organize resources in your project's {@code res/}
28directory, using various sub-directories that group resources by type and configuration.</p>
29
30<div class="figure" style="width:421px">
31<img src="{@docRoot}images/resources/resource_devices_diagram1.png" height="137" alt="" />
32<p class="img-caption">
33<strong>Figure 1.</strong> Two device configurations, both using default
34resources.</p>
35</div>
36
37<div class="figure" style="width:421px">
38<img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="137" alt="" />
39<p class="img-caption">
40<strong>Figure 2.</strong> Two device configurations, one using alternative
41resources.</p>
42</div>
43
44<p>For any type of resource, you can specify <em>default</em> and multiple
45<em>alternative</em> resources for your application:</p>
46<ul>
47  <li>Default resources are those that should be used regardless of
48the device configuration or when there are no alternative resources that match the current
49configuration.</li>
50  <li>Alternative resources are those that you've designed for use with a specific
51configuration. To specify that a group of resources are for a specific configuration,
52append an appropriate configuration qualifier to the directory name.</li>
53</ul>
54
55<p>For example, while your default UI
56layout is saved in the {@code res/layout/} directory, you might specify a different UI layout to
57be used when the screen is in landscape orientation, by saving it in the {@code res/layout-land/}
58directory. The Android system will automatically apply the appropriate resources by matching the
59device's current configuration to your resource directory names.</p>
60
61<p>Figure 1 demonstrates how a collection of default resources from an application will be applied
62to two different devices when there are no alternative resources available. Figure 2 shows
63the same application with a set of alternative resources that qualify for one of the device
64configurations, thus, the two devices uses different resources.</p>
65
66<p>The information above is just an introduction to how application resources work on Android.
67The following documents provide a complete guide to how you can organize your application resources,
68specify alternative resources, access them in your application, and more:</p>
69
70<dl>
71  <dt><strong><a href="providing-resources.html">Providing Resources</a></strong></dt>
72  <dd>What kinds of resources you can provide in your app, where to save them, and how to create
73alternative resources for specific device configurations.</dd>
74  <dt><strong><a href="accessing-resources.html">Accessing Resources</a></strong></dt>
75  <dd>How to use the resources you've provided, either by referencing them from your application
76code or from other XML resources.</dd>
77  <dt><strong><a href="runtime-changes.html">Handling Runtime Changes</a></strong></dt>
78  <dd>How to manage configuration changes that occur while your Activity is running.</dd>
79  <dt><strong><a href="localization.html">Localization</a></strong></dt>
80  <dd>A bottom-up guide to localizing your application using alternative resources. While this is
81just one specific use of alternative resources, it is very important in order to reach more
82users.</dd>
83  <dt><strong><a href="available-resources.html">Resource Types</a></strong></dt>
84  <dd>A reference of various resource types you can provide, describing their XML elements,
85attributes, and syntax. For example, this reference shows you how to create a resource for
86application menus, drawables, animations, and more.</dd>
87</dl>
88
89<!--
90<h2>Raw Assets</h2>
91
92<p>An alternative to saving files in {@code res/} is to save files in the {@code
93assets/} directory. This should only be necessary if you need direct access to original files and
94directories by name. Files saved in the {@code assets/} directory will not be given a resource
95ID, so you can't reference them through the {@code R} class or from XML resources. Instead, you can
96query data in the {@code assets/} directory like an ordinary file system, search through the
97directory and
98read raw data using {@link android.content.res.AssetManager}. For example, this can be more useful
99when dealing with textures for a game. However, if you only need to read raw data from a file
100(such as a video or audio file), then you should save files into the {@code res/raw/} directory and
101then read a stream of bytes using {@link android.content.res.Resources#openRawResource(int)}. This
102is uncommon, but if you need direct access to original files in {@code assets/}, refer to the {@link
103android.content.res.AssetManager} documentation.</p>
104-->
105