| page.title=More Resource Types |
| parent.title=Resource Types |
| parent.link=available-resources.html |
| @jd:body |
| |
| <p>This page defines more types of resources you can externalize, including:</p> |
| |
| <dl> |
| <dt><a href="#Bool">Bool</a></dt> |
| <dd>XML resource that carries a boolean value.</dd> |
| <dt><a href="#Color">Color</a></dt> |
| <dd>XML resource that carries a color value (a hexadecimal color).</dd> |
| <dt><a href="#Dimension">Dimension</a></dt> |
| <dd>XML resource that carries a dimension value (with a unit of measure).</dd> |
| <dt><a href="#Id">ID</a></dt> |
| <dd>XML resource that provides a unique identifier for application resources and |
| components.</dd> |
| <dt><a href="#Integer">Integer</a></dt> |
| <dd>XML resource that carries an integer value.</dd> |
| <dt><a href="#IntegerArray">Integer Array</a></dt> |
| <dd>XML resource that provides an array of integers.</dd> |
| <dt><a href="#TypedArray">Typed Array</a></dt> |
| <dd>XML resource that provides a {@link android.content.res.TypedArray} (which you can use |
| for an array of drawables).</dd> |
| </dl> |
| |
| |
| |
| |
| <h2 id="Bool">Bool</h2> |
| |
| <p>A boolean value defined in XML.</p> |
| |
| <p class="note"><strong>Note:</strong> A bool is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine bool resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename</em>.xml</code><br/> |
| The filename is arbitrary. The {@code <bool>} element's {@code name} will be used as the resource |
| ID.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.bool.<em>bool_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]bool/<em>bool_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#bool-resources-element">resources</a>> |
| <<a href="#bool-element">bool</a> |
| name="<em>bool_name</em>" |
| >[true | false]</bool> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| |
| <dt id="bool-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="bool-element"><code><bool></code></dt> |
| <dd>A boolean value: {@code true} or {@code false}. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>name</code></dt> |
| <dd><em>String</em>. A name for the bool value. This will be used as the resource ID.</dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> <!-- end elements and attributes --> |
| |
| <dt>example:</dt> |
| <dd>XML file saved at <code>res/values-small/bools.xml</code>: |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <bool name="screen_small">true</bool> |
| <bool name="adjust_view_bounds">true</bool> |
| </resources> |
| </pre> |
| |
| <p>This application code retrieves the boolean:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| boolean screenIsSmall = res.{@link android.content.res.Resources#getBoolean(int) getBoolean}(R.bool.screen_small); |
| </pre> |
| <p>This layout XML uses the boolean for an attribute:</p> |
| <pre> |
| <ImageView |
| android:layout_height="fill_parent" |
| android:layout_width="fill_parent" |
| android:src="@drawable/logo" |
| android:adjustViewBounds="@bool/adjust_view_bounds" /> |
| </pre> |
| </dd> <!-- end example --> |
| |
| </dl> |
| |
| |
| |
| |
| <h2 id="Color">Color</h2> |
| |
| <p>A color value defined in XML. |
| The color is specified with an RGB value and alpha channel. You can use a color resource |
| any place that accepts a hexadecimal color value. You can also use a color resource when a |
| drawable resource is expected in XML (for example, {@code android:drawable="@color/green"}).</p> |
| |
| <p>The value always begins with a pound (#) character and then followed by the |
| Alpha-Red-Green-Blue information in one of the following formats:</p> |
| <ul> |
| <li>#<em>RGB</em></li> |
| <li>#<em>ARGB</em></li> |
| <li>#<em>RRGGBB</em></li> |
| <li>#<em>AARRGGBB</em></li> |
| </ul> |
| |
| <p class="note"><strong>Note:</strong> A color is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine color resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/colors.xml</code><br/> |
| The filename is arbitrary. The {@code <color>} element's {@code name} will be used as the |
| resource ID.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.color.<em>color_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]color/<em>color_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#color-resources-element">resources</a>> |
| <<a href="#color-element">color</a> |
| name="<em>color_name</em>" |
| ><em>hex_color</em></color> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| |
| <dt id="color-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="color-element"><code><color></code></dt> |
| <dd>A color expressed in hexadecimal, as described above. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>name</code></dt> |
| <dd><em>String</em>. A name for the color. This will be used as the resource ID. |
| </dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> <!-- end elements and attributes --> |
| |
| <dt>example:</dt> |
| <dd>XML file saved at <code>res/values/colors.xml</code>: |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <color name="opaque_red">#f00</color> |
| <color name="translucent_red">#80ff0000</color> |
| </resources> |
| </pre> |
| |
| <p>This application code retrieves the color resource:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| int color = res.{@link android.content.res.Resources#getColor(int) getColor}(R.color.opaque_red); |
| </pre> |
| <p>This layout XML applies the color to an attribute:</p> |
| <pre> |
| <TextView |
| android:layout_width="fill_parent" |
| android:layout_height="wrap_content" |
| android:textColor="@color/translucent_red" |
| android:text="Hello"/> |
| </pre> |
| </dd> <!-- end example --> |
| |
| </dl> |
| |
| |
| |
| |
| |
| <h2 id="Dimension">Dimension</h2> |
| |
| <p>A dimension value defined in XML. A dimension |
| is specified with a number followed by a unit of measure. |
| For example: 10px, 2in, 5sp. The following units of measure are supported by Android:</p> |
| <dl> |
| <dt>{@code dp}</dt> |
| <dd>Density-independent Pixels - An abstract unit that is based on the physical density of the |
| screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal |
| to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up |
| by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number |
| of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, |
| but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution |
| to making the view dimensions in your layout resize properly for different screen densities. In |
| other words, it provides consistency for the real-world sizes of your UI elements across different |
| devices.</dd> |
| <dt>{@code sp}</dt> |
| <dd>Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font |
| size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted |
| for both the screen density and the user's preference.</dd> |
| <dt>{@code pt}</dt> |
| <dd>Points - 1/72 of an inch based on the physical size of the screen.</dd> |
| <dt>{@code px}</dt> |
| <dd>Pixels - Corresponds to actual pixels on the screen. This unit of measure is not recommended because |
| the actual representation can vary across devices; each devices may have a different number of pixels |
| per inch and may have more or fewer total pixels available on the screen.</dd> |
| <dt>{@code mm}</dt> |
| <dd>Millimeters - Based on the physical size of the screen.</dd> |
| <dt>{@code in}</dt> |
| <dd>Inches - Based on the physical size of the screen.</dd> |
| </dl> |
| |
| <p class="note"><strong>Note:</strong> A dimension is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine dimension resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename</em>.xml</code><br/> |
| The filename is arbitrary. The {@code <dimen>} element's {@code name} will be used as the |
| resource ID.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.dimen.<em>dimension_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]dimen/<em>dimension_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#dimen-resources-element">resources</a>> |
| <<a href="#dimen-element">dimen</a> |
| name="<em>dimension_name</em>" |
| ><em>dimension</em></dimen> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| |
| <dt id="dimen-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="dimen-element"><code><dimen></code></dt> |
| <dd>A dimension, represented by a float, followed by a unit of measurement (dp, sp, pt, px, mm, in), |
| as described above. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>name</code></dt> |
| <dd><em>String</em>. A name for the dimension. This will be used as the resource ID. |
| </dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> <!-- end elements and attributes --> |
| |
| <dt>example:</dt> |
| <dd>XML file saved at <code>res/values/dimens.xml</code>: |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <dimen name="textview_height">25dp</dimen> |
| <dimen name="textview_width">150dp</dimen> |
| <dimen name="ball_radius">30dp</dimen> |
| <dimen name="font_size">16sp</dimen> |
| </resources> |
| </pre> |
| |
| <p>This application code retrieves a dimension:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| float fontSize = res.{@link android.content.res.Resources#getDimension(int) getDimension}(R.dimen.font_size); |
| </pre> |
| <p>This layout XML applies dimensions to attributes:</p> |
| <pre> |
| <TextView |
| android:layout_height="@dimen/textview_height" |
| android:layout_width="@dimen/textview_width" |
| android:textSize="@dimen/font_size"/> |
| </pre> |
| </dl> |
| </dd> <!-- end example --> |
| |
| </dl> |
| |
| |
| |
| |
| |
| |
| <h2 id="Id">ID</h2> |
| |
| <p>A unique resource ID defined in XML. Using the name you provide in the {@code <item>} |
| element, the Android developer tools create a unique integer in your project's {@code |
| R.java} class, which you can use as an |
| identifier for an application resources (for example, a {@link android.view.View} in your UI layout) |
| or a unique integer for use in your application code (for example, as an ID for a dialog or a |
| result code).</p> |
| |
| <p class="note"><strong>Note:</strong> An ID is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine ID resources with other simple resources in the one XML file, |
| under one {@code <resources>} element. Also, remember that an ID resources does not reference |
| an actual resource item; it is simply a unique ID that you can attach to other resources or use |
| as a unique integer in your application.</p> |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename.xml</em></code><br/> |
| The filename is arbitrary.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.id.<em>name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]id/<em>name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#id-resources-element">resources</a>> |
| <<a href="#id-item-element">item</a> |
| type="id" |
| name="<em>id_name</em>" /> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| |
| <dt id="id-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="id-item-element"><code><item></code></dt> |
| <dd>Defines a unique ID. Takes no value, only attributes. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>type</code></dt> |
| <dd>Must be "id".</dd> |
| <dt><code>name</code></dt> |
| <dd><em>String</em>. A unique name for the ID.</dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> <!-- end elements and attributes --> |
| |
| <dt>example:</dt> |
| <dd> |
| <p>XML file saved at <code>res/values/ids.xml</code>:</p> |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <item type="id" name="button_ok" /> |
| <item type="id" name="dialog_exit" /> |
| </resources> |
| </pre> |
| |
| <p>Then, this layout snippet uses the "button_ok" ID for a Button widget:</p> |
| <pre> |
| <Button android:id="<b>@id/button_ok</b>" |
| style="@style/button_style" /> |
| </pre> |
| |
| <p>Notice that the {@code android:id} value does not include the plus sign in the ID reference, |
| because the ID already exists, as defined in the {@code ids.xml} example above. (When you specify an |
| ID to an XML resource using the plus sign—in the format {@code |
| android:id="@+id/name"}—it means that the "name" ID does not exist and should be created.)</p> |
| |
| <p>As another example, the following code snippet uses the "dialog_exit" ID as a unique identifier |
| for a dialog:</p> |
| <pre> |
| {@link android.app.Activity#showDialog(int) showDialog}(<b>R.id.dialog_exit</b>); |
| </pre> |
| <p>In the same application, the "dialog_exit" ID is compared when creating a dialog:</p> |
| <pre> |
| protected Dialog {@link android.app.Activity#onCreateDialog(int)}(int id) { |
| Dialog dialog; |
| switch(id) { |
| case <b>R.id.dialog_exit</b>: |
| ... |
| break; |
| default: |
| dialog = null; |
| } |
| return dialog; |
| } |
| </pre> |
| </dd> <!-- end example --> |
| |
| |
| </dl> |
| |
| |
| |
| |
| |
| <h2 id="Integer">Integer</h2> |
| |
| <p>An integer defined in XML.</p> |
| |
| <p class="note"><strong>Note:</strong> An integer is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine integer resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename.xml</em></code><br/> |
| The filename is arbitrary. The {@code <integer>} element's {@code name} will be used as the |
| resource ID.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.integer.<em>integer_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]integer/<em>integer_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#integer-resources-element">resources</a>> |
| <<a href="#integer-element">integer</a> |
| name="<em>integer_name</em>" |
| ><em>integer</em></integer> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| |
| <dt id="integer-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="integer-element"><code><integer></code></dt> |
| <dd>An integer. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>name</code></dt> |
| <dd><em>String</em>. A name for the integer. This will be used as the resource ID. |
| </dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> <!-- end elements and attributes --> |
| |
| <dt>example:</dt> |
| <dd> |
| <p>XML file saved at <code>res/values/integers.xml</code>:</p> |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <integer name="max_speed">75</integer> |
| <integer name="min_speed">5</integer> |
| </resources> |
| </pre> |
| <p>This application code retrieves an integer:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| int maxSpeed = res.{@link android.content.res.Resources#getInteger(int) getInteger}(R.integer.max_speed); |
| </pre> |
| </dd> <!-- end example --> |
| |
| |
| </dl> |
| |
| |
| |
| |
| |
| <h2 id="IntegerArray">Integer Array</h2> |
| |
| <p>An array of integers defined in XML.</p> |
| |
| <p class="note"><strong>Note:</strong> An integer array is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine integer array resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename</em>.xml</code><br/> |
| The filename is arbitrary. The {@code <integer-array>} element's {@code name} will be used as the |
| resource ID.</dd> |
| |
| <dt>compiled resource datatype:</dt> |
| <dd>Resource pointer to an array of integers.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.array.<em>integer_array_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]array.<em>integer_array_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#integer-array-resources-element">resources</a>> |
| <<a href="#integer-array-element">integer-array</a> |
| name="<em>integer_array_name</em>"> |
| <<a href="#integer-array-item-element">item</a> |
| ><em>integer</em></item> |
| </integer-array> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| <dt id="integer-array-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="integer-array-element"><code><integer-array></code></dt> |
| <dd>Defines an array of integers. Contains one or more child {@code <item>} elements. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>android:name</code></dt> |
| <dd><em>String</em>. A name for the array. This name will be used as the resource |
| ID to reference the array.</dd> |
| </dl> |
| </dd> |
| <dt id="integer-array-item-element"><code><item></code></dt> |
| <dd>An integer. The value can be a reference to another |
| integer resource. Must be a child of a {@code <integer-array>} element. |
| <p>No attributes.</p> |
| </dd> |
| </dl> |
| </dd> <!-- end elements --> |
| |
| <dt>example:</dt> |
| <dd>XML file saved at <code>res/values/integers.xml</code>: |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <integer-array name="bits"> |
| <item>4</item> |
| <item>8</item> |
| <item>16</item> |
| <item>32</item> |
| </integer-array> |
| </resources> |
| </pre> |
| |
| <p>This application code retrieves the integer array:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| int[] bits = res.{@link android.content.res.Resources#getIntArray(int) getIntArray}(R.array.bits); |
| </pre> |
| </dd> <!-- end example --> |
| |
| </dl> |
| |
| |
| |
| |
| |
| <h2 id="TypedArray">Typed Array</h2> |
| |
| <p>A {@link android.content.res.TypedArray} defined in XML. You can use |
| this to create an array of other resources, such as drawables. Note that the array |
| is not required to be homogeneous, so you can create an array of mixed resource types, but |
| you must be aware of what and where the data types are in the array so that you can properly obtain |
| each item with the {@link android.content.res.TypedArray}'s {@code get...()} methods.</p> |
| |
| <p class="note"><strong>Note:</strong> A typed array is a simple resource that is referenced |
| using the value provided in the {@code name} attribute (not the name of the XML file). As |
| such, you can combine typed array resources with other simple resources in the one XML file, |
| under one {@code <resources>} element.</p> |
| |
| |
| <dl class="xml"> |
| |
| <dt>file location:</dt> |
| <dd><code>res/values/<em>filename</em>.xml</code><br/> |
| The filename is arbitrary. The {@code <array>} element's {@code name} will be used as the |
| resource ID.</dd> |
| |
| <dt>compiled resource datatype:</dt> |
| <dd>Resource pointer to a {@link android.content.res.TypedArray}.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd> |
| In Java: <code>R.array.<em>array_name</em></code><br/> |
| In XML: <code>@[<em>package</em>:]array.<em>array_name</em></code> |
| </dd> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| <?xml version="1.0" encoding="utf-8"?> |
| <<a href="#array-resources-element">resources</a>> |
| <<a href="#array-element">array</a> |
| name="<em>integer_array_name</em>"> |
| <<a href="#array-item-element">item</a>><em>resource</em></item> |
| </array> |
| </resources> |
| </pre> |
| </dd> |
| |
| <dt>elements:</dt> |
| <dd> |
| <dl class="tag-list"> |
| <dt id="array-resources-element"><code><resources></code></dt> |
| <dd><strong>Required.</strong> This must be the root node. |
| <p>No attributes.</p> |
| </dd> |
| <dt id="array-element"><code><array></code></dt> |
| <dd>Defines an array. Contains one or more child {@code <item>} elements. |
| <p class="caps">attributes:</p> |
| <dl class="atn-list"> |
| <dt><code>android:name</code></dt> |
| <dd><em>String</em>. A name for the array. This name will be used as the resource |
| ID to reference the array.</dd> |
| </dl> |
| </dd> |
| <dt id="array-item-element"><code><item></code></dt> |
| <dd>A generic resource. The value can be a reference to a resource or a simple data type. |
| Must be a child of an {@code <array>} element. |
| <p>No attributes.</p> |
| </dd> |
| </dl> |
| </dd> <!-- end elements --> |
| |
| <dt>example:</dt> |
| <dd>XML file saved at <code>res/values/arrays.xml</code>: |
| <pre> |
| <?xml version="1.0" encoding="utf-8"?> |
| <resources> |
| <array name="icons"> |
| <item>@drawable/home</item> |
| <item>@drawable/settings</item> |
| <item>@drawable/logout</item> |
| </array> |
| <array name="colors"> |
| <item>#FFFF0000</item> |
| <item>#FF00FF00</item> |
| <item>#FF0000FF</item> |
| </array> |
| </resources> |
| </pre> |
| |
| <p>This application code retrieves each array and then obtains the first entry in each array:</p> |
| <pre> |
| Resources res = {@link android.content.Context#getResources()}; |
| TypedArray icons = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.icons); |
| Drawable drawable = icons.{@link android.content.res.TypedArray#getDrawable(int) getDrawable}(0); |
| |
| TypedArray colors = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.colors); |
| int color = colors.{@link android.content.res.TypedArray#getColor(int,int) getColor}(0,0); |
| </pre> |
| </dd> <!-- end example --> |
| |
| </dl> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <!-- TODO |
| |
| |
| <h2>Styleable Attribute</h2> |
| |
| |
| <dl class="xml"> |
| |
| <dt>syntax:</dt> |
| <dd> |
| <pre class="stx"> |
| </pre> |
| </dd> |
| |
| <dt>file location:</dt> |
| <dd><code>res/</code></dd> |
| |
| <dt>compiled resource datatype:</dt> |
| <dd>Resource pointer to a {@link android.view.Menu} (or subclass) resource.</dd> |
| |
| <dt>resource reference:</dt> |
| <dd>Java: <code>R.</code><br/> |
| XML: |
| </dd> |
| |
| <dt>elements and attributes:</dt> |
| <dd> |
| <dl class="attr"> |
| |
| <dt><code></code></dt> |
| <dd></dd> |
| <dt><code></code></dt> |
| <dd>Valid attributes: |
| <dl> |
| <dt><code></code></dt> |
| <dd> |
| </dd> |
| <dt><code></code></dt> |
| <dd> |
| </dd> |
| </dl> |
| </dd> |
| |
| </dl> |
| </dd> |
| |
| <dt>example:</dt> |
| <dd> |
| <dl> |
| |
| <dt>XML file saved at <code>res/</code>:</dt> |
| <dd> |
| <pre> |
| |
| </pre> |
| </dd> |
| |
| <dt>Java code :</dt> |
| <dd> |
| <pre> |
| |
| </pre> |
| </dd> |
| |
| </dl> |
| </dd> |
| |
| |
| <dt>see also:</dt> |
| <dd> |
| <ul> |
| <li></li> |
| </ul> |
| </dd> |
| |
| </dl> |
| |
| |
| |
| |
| |
| |
| --> |
| |
| |
| |
| |