1 page.title=Resources Overview 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 <li><a href="complex-xml-resources.html">Complex XML Resources</a></li> 13 </ol> 14 15 <h2>Reference</h2> 16 <ol> 17 <li><a href="available-resources.html">Resource Types</a></li> 18 </ol> 19 </div> 20 </div> 21 22 23 <p>You should always externalize resources such as images and strings from your application 24 code, so that you can maintain them independently. Externalizing your 25 resources also allows you to provide alternative resources that support specific device 26 configurations such as different languages or screen sizes, which becomes increasingly 27 important as more Android-powered devices become available with different configurations. In order 28 to provide compatibility with different configurations, you must organize resources in your 29 project's {@code res/} directory, using various sub-directories that group resources by type and 30 configuration.</p> 31 32 <div class="figure" style="width:429px"> 33 <img src="{@docRoot}images/resources/resource_devices_diagram1.png" height="167" alt="" /> 34 <p class="img-caption"> 35 <strong>Figure 1.</strong> Two different devices, each using the default layout 36 (the app provides no alternative layouts).</p> 37 </div> 38 39 <div class="figure" style="width:429px"> 40 <img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="167" alt="" /> 41 <p class="img-caption"> 42 <strong>Figure 2.</strong> Two different devices, each using a different layout provided 43 for different screen sizes.</p> 44 </div> 45 46 <p>For any type of resource, you can specify <em>default</em> and multiple 47 <em>alternative</em> resources for your application:</p> 48 <ul> 49 <li>Default resources are those that should be used regardless of 50 the device configuration or when there are no alternative resources that match the current 51 configuration.</li> 52 <li>Alternative resources are those that you've designed for use with a specific 53 configuration. To specify that a group of resources are for a specific configuration, 54 append an appropriate configuration qualifier to the directory name.</li> 55 </ul> 56 57 <p>For example, while your default UI 58 layout is saved in the {@code res/layout/} directory, you might specify a different layout to 59 be used when the screen is in landscape orientation, by saving it in the {@code res/layout-land/} 60 directory. Android automatically applies the appropriate resources by matching the 61 device's current configuration to your resource directory names.</p> 62 63 <p>Figure 1 illustrates how the system applies the same layout for 64 two different devices when there are no alternative resources available. Figure 2 shows 65 the same application when it adds an alternative layout resource for larger screens.</p> 66 67 <p>The following documents provide a complete guide to how you can organize your application resources, 68 specify 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 73 alternative 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 76 code 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 81 just one specific use of alternative resources, it is very important in order to reach more 82 users.</dd> 83 <dt><strong><a href="complex-xml-resources.html">Complex XML Resources</a></strong></dt> 84 <dd>An XML format for building complex resources like animated vector drawables in a single 85 XML file.</dd> 86 <dt><strong><a href="available-resources.html">Resource Types</a></strong></dt> 87 <dd>A reference of various resource types you can provide, describing their XML elements, 88 attributes, and syntax. For example, this reference shows you how to create a resource for 89 application menus, drawables, animations, and more.</dd> 90 </dl> 91 92 <!-- 93 <h2>Raw Assets</h2> 94 95 <p>An alternative to saving files in {@code res/} is to save files in the {@code 96 assets/} directory. This should only be necessary if you need direct access to original files and 97 directories by name. Files saved in the {@code assets/} directory will not be given a resource 98 ID, so you can't reference them through the {@code R} class or from XML resources. Instead, you can 99 query data in the {@code assets/} directory like an ordinary file system, search through the 100 directory and 101 read raw data using {@link android.content.res.AssetManager}. For example, this can be more useful 102 when dealing with textures for a game. However, if you only need to read raw data from a file 103 (such as a video or audio file), then you should save files into the {@code res/raw/} directory and 104 then read a stream of bytes using {@link android.content.res.Resources#openRawResource(int)}. This 105 is uncommon, but if you need direct access to original files in {@code assets/}, refer to the {@link 106 android.content.res.AssetManager} documentation.</p> 107 --> 108