Home | History | Annotate | Download | only in resources
      1 page.title=More Resource Types
      2 parent.title=Resource Types
      3 parent.link=available-resources.html
      4 @jd:body
      5 
      6 <p>This page defines more types of resources you can externalize, including:</p>
      7 
      8 <dl>
      9   <dt><a href="#Bool">Bool</a></dt>
     10     <dd>XML resource that carries a boolean value.</dd>
     11   <dt><a href="#Color">Color</a></dt>
     12     <dd>XML resource that carries a color value (a hexadecimal color).</dd>
     13   <dt><a href="#Dimension">Dimension</a></dt>
     14     <dd>XML resource that carries a dimension value (with a unit of measure).</dd>
     15   <dt><a href="#Id">ID</a></dt>
     16     <dd>XML resource that provides a unique identifier for application resources and
     17 components.</dd>
     18   <dt><a href="#Integer">Integer</a></dt>
     19     <dd>XML resource that carries an integer value.</dd>
     20   <dt><a href="#IntegerArray">Integer Array</a></dt>
     21     <dd>XML resource that provides an array of integers.</dd>
     22   <dt><a href="#TypedArray">Typed Array</a></dt>
     23     <dd>XML resource that provides a {@link android.content.res.TypedArray} (which you can use
     24 for an array of drawables).</dd>
     25 </dl>
     26 
     27 
     28 
     29 
     30 <h2 id="Bool">Bool</h2>
     31 
     32 <p>A boolean value defined in XML.</p>
     33 
     34 <p class="note"><strong>Note:</strong> A bool is a simple resource that is referenced
     35 using the value provided in the {@code name} attribute (not the name of the XML file). As
     36 such, you can combine bool resources with other simple resources in the one XML file,
     37 under one {@code &lt;resources>} element.</p>
     38 
     39 <dl class="xml">
     40 
     41 <dt>file location:</dt>
     42 <dd><code>res/values/<em>filename</em>.xml</code><br/>
     43 The filename is arbitrary. The {@code &lt;bool>} element's {@code name} will be used as the resource
     44 ID.</dd>
     45 
     46 <dt>resource reference:</dt>
     47 <dd>
     48 In Java: <code>R.bool.<em>bool_name</em></code><br/>
     49 In XML: <code>@[<em>package</em>:]bool/<em>bool_name</em></code>
     50 </dd>
     51 
     52 <dt>syntax:</dt>
     53 <dd>
     54 <pre class="stx">
     55 &lt;?xml version="1.0" encoding="utf-8"?>
     56 &lt;<a href="#bool-resources-element">resources</a>&gt;
     57     &lt;<a href="#bool-element">bool</a>
     58         name="<em>bool_name</em>"
     59         &gt;[true | false]&lt;/bool>
     60 &lt;/resources>
     61 </pre>
     62 </dd>
     63 
     64 <dt>elements:</dt>
     65 <dd>
     66 <dl class="tag-list">
     67 
     68   <dt id="bool-resources-element"><code>&lt;resources&gt;</code></dt>
     69     <dd><strong>Required.</strong> This must be the root node.
     70       <p>No attributes.</p>
     71     </dd>
     72   <dt id="bool-element"><code>&lt;bool&gt;</code></dt>
     73     <dd>A boolean value: {@code true} or {@code false}.
     74       <p class="caps">attributes:</p>
     75       <dl class="atn-list">
     76         <dt><code>name</code></dt>
     77         <dd><em>String</em>. A name for the bool value. This will be used as the resource ID.</dd>
     78       </dl>
     79     </dd>
     80 
     81 </dl>
     82 </dd> <!-- end  elements and attributes -->
     83 
     84 <dt>example:</dt>
     85 <dd>XML file saved at <code>res/values-small/bools.xml</code>:
     86 <pre>
     87 &lt;?xml version="1.0" encoding="utf-8"?>
     88 &lt;resources&gt;
     89     &lt;bool name="screen_small">true&lt;/bool>
     90     &lt;bool name="adjust_view_bounds">true&lt;/bool>
     91 &lt;/resources>
     92 </pre>
     93 
     94   <p>This application code retrieves the boolean:</p>
     95 <pre>
     96 Resources res = {@link android.content.Context#getResources()};
     97 boolean screenIsSmall = res.{@link android.content.res.Resources#getBoolean(int) getBoolean}(R.bool.screen_small);
     98 </pre>
     99   <p>This layout XML uses the boolean for an attribute:</p>
    100 <pre>
    101 &lt;ImageView
    102     android:layout_height="fill_parent"
    103     android:layout_width="fill_parent"
    104     android:src="@drawable/logo"
    105     android:adjustViewBounds="@bool/adjust_view_bounds" />
    106 </pre>
    107 </dd> <!-- end example -->
    108 
    109 </dl>
    110 
    111 
    112 
    113 
    114 <h2 id="Color">Color</h2>
    115 
    116 <p>A color value defined in XML.
    117 The color is specified with an RGB value and alpha channel. You can use a color resource
    118 any place that accepts a hexadecimal color value. You can also use a color resource when a
    119 drawable resource is expected in XML (for example, {@code android:drawable="@color/green"}).</p>
    120 
    121 <p>The value always begins with a pound (#) character and then followed by the
    122 Alpha-Red-Green-Blue information in one of the following formats:</p>
    123 <ul>
    124   <li>#<em>RGB</em></li>
    125   <li>#<em>ARGB</em></li>
    126   <li>#<em>RRGGBB</em></li>
    127   <li>#<em>AARRGGBB</em></li>
    128 </ul>
    129 
    130 <p class="note"><strong>Note:</strong> A color is a simple resource that is referenced
    131 using the value provided in the {@code name} attribute (not the name of the XML file). As
    132 such, you can combine color resources with other simple resources in the one XML file,
    133 under one {@code &lt;resources>} element.</p>
    134 
    135 <dl class="xml">
    136 
    137 <dt>file location:</dt>
    138 <dd><code>res/values/colors.xml</code><br/>
    139 The filename is arbitrary. The {@code &lt;color>} element's {@code name} will be used as the
    140 resource ID.</dd>
    141 
    142 <dt>resource reference:</dt>
    143 <dd>
    144 In Java: <code>R.color.<em>color_name</em></code><br/>
    145 In XML: <code>@[<em>package</em>:]color/<em>color_name</em></code>
    146 </dd>
    147 
    148 <dt>syntax:</dt>
    149 <dd>
    150 <pre class="stx">
    151 &lt;?xml version="1.0" encoding="utf-8"?>
    152 &lt;<a href="#color-resources-element">resources</a>>
    153     &lt;<a href="#color-element">color</a>
    154         name="<em>color_name</em>"
    155         &gt;<em>hex_color</em>&lt;/color>
    156 &lt;/resources>
    157 </pre>
    158 </dd>
    159 
    160 <dt>elements:</dt>
    161 <dd>
    162 <dl class="tag-list">
    163 
    164   <dt id="color-resources-element"><code>&lt;resources&gt;</code></dt>
    165     <dd><strong>Required.</strong> This must be the root node.
    166       <p>No attributes.</p>
    167     </dd>
    168   <dt id="color-element"><code>&lt;color&gt;</code></dt>
    169     <dd>A color expressed in hexadecimal, as described above.
    170       <p class="caps">attributes:</p>
    171       <dl class="atn-list">
    172         <dt><code>name</code></dt>
    173         <dd><em>String</em>. A name for the color. This will be used as the resource ID.
    174         </dd>
    175       </dl>
    176     </dd>
    177 
    178 </dl>
    179 </dd> <!-- end  elements and attributes -->
    180 
    181 <dt>example:</dt>
    182 <dd>XML file saved at <code>res/values/colors.xml</code>:
    183 <pre>
    184 &lt;?xml version="1.0" encoding="utf-8"?>
    185 &lt;resources>
    186    &lt;color name="opaque_red">#f00&lt;/color>
    187    &lt;color name="translucent_red">#80ff0000&lt;/color>
    188 &lt;/resources>
    189 </pre>
    190 
    191     <p>This application code retrieves the color resource:</p>
    192 <pre>
    193 Resources res = {@link android.content.Context#getResources()};
    194 int color = res.{@link android.content.res.Resources#getColor(int) getColor}(R.color.opaque_red);
    195 </pre>
    196   <p>This layout XML applies the color to an attribute:</p>
    197 <pre>
    198 &lt;TextView
    199     android:layout_width="fill_parent"
    200     android:layout_height="wrap_content"
    201     android:textColor="@color/translucent_red"
    202     android:text="Hello"/>
    203 </pre>
    204 </dd> <!-- end example -->
    205 
    206 </dl>
    207 
    208 
    209 
    210 
    211 
    212 <h2 id="Dimension">Dimension</h2>
    213 
    214 <p>A dimension value defined in XML. A dimension
    215 is specified with a number followed by a unit of measure.
    216 For example: 10px, 2in, 5sp. The following units of measure are supported by Android:</p>
    217 <dl>
    218   <dt>{@code dp}</dt>
    219     <dd>Density-independent Pixels - An abstract unit that is based on the physical density of the
    220 screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal
    221 to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up
    222 by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number
    223 of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density,
    224 but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution
    225 to making the view dimensions in your layout resize properly for different screen densities. In
    226 other words, it provides consistency for the real-world sizes of your UI elements across different
    227 devices.</dd>
    228   <dt>{@code sp}</dt>
    229     <dd>Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font
    230     size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted
    231     for both the screen density and the user's preference.</dd>
    232   <dt>{@code pt}</dt>
    233     <dd>Points - 1/72 of an inch based on the physical size of the screen.</dd>
    234   <dt>{@code px}</dt>
    235     <dd>Pixels - Corresponds to actual pixels on the screen. This unit of measure is not recommended because
    236     the actual representation can vary across devices; each devices may have a different number of pixels
    237     per inch and may have more or fewer total pixels available on the screen.</dd>
    238   <dt>{@code mm}</dt>
    239     <dd>Millimeters - Based on the physical size of the screen.</dd>
    240   <dt>{@code in}</dt>
    241     <dd>Inches - Based on the physical size of the screen.</dd>
    242 </dl>
    243 
    244 <p class="note"><strong>Note:</strong> A dimension is a simple resource that is referenced
    245 using the value provided in the {@code name} attribute (not the name of the XML file). As
    246 such, you can combine dimension resources with other simple resources in the one XML file,
    247 under one {@code &lt;resources>} element.</p>
    248 
    249 <dl class="xml">
    250 
    251 <dt>file location:</dt>
    252 <dd><code>res/values/<em>filename</em>.xml</code><br/>
    253 The filename is arbitrary. The {@code &lt;dimen>} element's {@code name} will be used as the
    254 resource ID.</dd>
    255 
    256 <dt>resource reference:</dt>
    257 <dd>
    258 In Java: <code>R.dimen.<em>dimension_name</em></code><br/>
    259 In XML: <code>@[<em>package</em>:]dimen/<em>dimension_name</em></code>
    260 </dd>
    261 
    262 <dt>syntax:</dt>
    263 <dd>
    264 <pre class="stx">
    265 &lt;?xml version="1.0" encoding="utf-8"?>
    266 &lt;<a href="#dimen-resources-element">resources</a>>
    267     &lt;<a href="#dimen-element">dimen</a>
    268         name="<em>dimension_name</em>"
    269         &gt;<em>dimension</em>&lt;/dimen&gt;
    270 &lt;/resources&gt;
    271 </pre>
    272 </dd>
    273 
    274 <dt>elements:</dt>
    275 <dd>
    276 <dl class="tag-list">
    277 
    278   <dt id="dimen-resources-element"><code>&lt;resources&gt;</code></dt>
    279     <dd><strong>Required.</strong> This must be the root node.
    280       <p>No attributes.</p>
    281     </dd>
    282   <dt id="dimen-element"><code>&lt;dimen&gt;</code></dt>
    283     <dd>A dimension, represented by a float, followed by a unit of measurement (dp, sp, pt, px, mm, in),
    284       as described above.
    285       <p class="caps">attributes:</p>
    286       <dl class="atn-list">
    287         <dt><code>name</code></dt>
    288         <dd><em>String</em>. A name for the dimension. This will be used as the resource ID.
    289         </dd>
    290       </dl>
    291     </dd>
    292 
    293 </dl>
    294 </dd> <!-- end  elements and attributes -->
    295 
    296 <dt>example:</dt>
    297 <dd>XML file saved at <code>res/values/dimens.xml</code>:
    298 <pre>
    299 &lt;?xml version="1.0" encoding="utf-8"?>
    300 &lt;resources>
    301     &lt;dimen name="textview_height">25dp&lt;/dimen>
    302     &lt;dimen name="textview_width">150dp&lt;/dimen>
    303     &lt;dimen name="ball_radius">30dp&lt;/dimen>
    304     &lt;dimen name="font_size">16sp&lt;/dimen>
    305 &lt;/resources>
    306 </pre>
    307 
    308     <p>This application code retrieves a dimension:</p>
    309 <pre>
    310 Resources res = {@link android.content.Context#getResources()};
    311 float fontSize = res.{@link android.content.res.Resources#getDimension(int) getDimension}(R.dimen.font_size);
    312 </pre>
    313   <p>This layout XML applies dimensions to attributes:</p>
    314 <pre>
    315 &lt;TextView
    316     android:layout_height="@dimen/textview_height"
    317     android:layout_width="@dimen/textview_width"
    318     android:textSize="@dimen/font_size"/>
    319 </pre>
    320   </dl>
    321 </dd> <!-- end example -->
    322 
    323 </dl>
    324 
    325 
    326 
    327 
    328 
    329 
    330 <h2 id="Id">ID</h2>
    331 
    332 <p>A unique resource ID defined in XML. Using the name you provide in the {@code &lt;item&gt;}
    333 element, the Android developer tools create a unique integer in your project's {@code
    334 R.java} class, which you can use as an
    335 identifier for an application resources (for example, a {@link android.view.View} in your UI layout)
    336 or a unique integer for use in your application code (for example, as an ID for a dialog or a
    337 result code).</p>
    338 
    339 <p class="note"><strong>Note:</strong> An ID is a simple resource that is referenced
    340 using the value provided in the {@code name} attribute (not the name of the XML file). As
    341 such, you can combine ID resources with other simple resources in the one XML file,
    342 under one {@code &lt;resources&gt;} element. Also, remember that an ID resources does not reference
    343 an actual resource item; it is simply a unique ID that you can attach to other resources or use
    344 as a unique integer in your application.</p>
    345 
    346 <dl class="xml">
    347 
    348 <dt>file location:</dt>
    349 <dd><code>res/values/<em>filename.xml</em></code><br/>
    350 The filename is arbitrary.</dd>
    351 
    352 <dt>resource reference:</dt>
    353 <dd>
    354 In Java: <code>R.id.<em>name</em></code><br/>
    355 In XML: <code>@[<em>package</em>:]id/<em>name</em></code>
    356 </dd>
    357 
    358 <dt>syntax:</dt>
    359 <dd>
    360 <pre class="stx">
    361 &lt;?xml version="1.0" encoding="utf-8"?>
    362 &lt;<a href="#id-resources-element">resources</a>&gt;
    363     &lt;<a href="#id-item-element">item</a>
    364         type="id"
    365         name="<em>id_name</em>" /&gt;
    366 &lt;/resources&gt;
    367 </pre>
    368 </dd>
    369 
    370 <dt>elements:</dt>
    371 <dd>
    372 <dl class="tag-list">
    373 
    374   <dt id="id-resources-element"><code>&lt;resources&gt;</code></dt>
    375     <dd><strong>Required.</strong> This must be the root node.
    376       <p>No attributes.</p>
    377     </dd>
    378   <dt id="id-item-element"><code>&lt;item&gt;</code></dt>
    379     <dd>Defines a unique ID. Takes no value, only attributes.
    380       <p class="caps">attributes:</p>
    381       <dl class="atn-list">
    382         <dt><code>type</code></dt>
    383         <dd>Must be "id".</dd>
    384         <dt><code>name</code></dt>
    385         <dd><em>String</em>. A unique name for the ID.</dd>
    386       </dl>
    387     </dd>
    388 
    389 </dl>
    390 </dd> <!-- end  elements and attributes -->
    391 
    392 <dt>example:</dt>
    393 <dd>
    394   <p>XML file saved at <code>res/values/ids.xml</code>:</p>
    395 <pre>
    396 &lt;?xml version="1.0" encoding="utf-8"?>
    397 &lt;resources>
    398     &lt;item type="id" name="button_ok" /&gt;
    399     &lt;item type="id" name="dialog_exit" /&gt;
    400 &lt;/resources>
    401 </pre>
    402 
    403     <p>Then, this layout snippet uses the "button_ok" ID for a Button widget:</p>
    404 <pre>
    405 &lt;Button android:id="<b>@id/button_ok</b>"
    406     style="@style/button_style" /&gt;
    407 </pre>
    408 
    409     <p>Notice that the {@code android:id} value does not include the plus sign in the ID reference,
    410 because the ID already exists, as defined in the {@code ids.xml} example above. (When you specify an
    411 ID to an XML resource using the plus sign&mdash;in the format {@code
    412 android:id="@+id/name"}&mdash;it means that the "name" ID does not exist and should be created.)</p>
    413 
    414   <p>As another example, the following code snippet uses the "dialog_exit" ID as a unique identifier
    415 for a dialog:</p>
    416 <pre>
    417 {@link android.app.Activity#showDialog(int) showDialog}(<b>R.id.dialog_exit</b>);
    418 </pre>
    419   <p>In the same application, the "dialog_exit" ID is compared when creating a dialog:</p>
    420 <pre>
    421 protected Dialog {@link android.app.Activity#onCreateDialog(int)}(int id) {
    422     Dialog dialog;
    423     switch(id) {
    424     case <b>R.id.dialog_exit</b>:
    425         ...
    426         break;
    427     default:
    428         dialog = null;
    429     }
    430     return dialog;
    431 }
    432 </pre>
    433 </dd> <!-- end example -->
    434 
    435 
    436 </dl>
    437 
    438 
    439 
    440 
    441 
    442 <h2 id="Integer">Integer</h2>
    443 
    444 <p>An integer defined in XML.</p>
    445 
    446 <p class="note"><strong>Note:</strong> An integer is a simple resource that is referenced
    447 using the value provided in the {@code name} attribute (not the name of the XML file). As
    448 such, you can combine integer resources with other simple resources in the one XML file,
    449 under one {@code &lt;resources>} element.</p>
    450 
    451 <dl class="xml">
    452 
    453 <dt>file location:</dt>
    454 <dd><code>res/values/<em>filename.xml</em></code><br/>
    455 The filename is arbitrary. The {@code &lt;integer>} element's {@code name} will be used as the
    456 resource ID.</dd>
    457 
    458 <dt>resource reference:</dt>
    459 <dd>
    460 In Java: <code>R.integer.<em>integer_name</em></code><br/>
    461 In XML: <code>@[<em>package</em>:]integer/<em>integer_name</em></code>
    462 </dd>
    463 
    464 <dt>syntax:</dt>
    465 <dd>
    466 <pre class="stx">
    467 &lt;?xml version="1.0" encoding="utf-8"?>
    468 &lt;<a href="#integer-resources-element">resources</a>>
    469     &lt;<a href="#integer-element">integer</a>
    470         name="<em>integer_name</em>"
    471         &gt;<em>integer</em>&lt;/integer&gt;
    472 &lt;/resources&gt;
    473 </pre>
    474 </dd>
    475 
    476 <dt>elements:</dt>
    477 <dd>
    478 <dl class="tag-list">
    479 
    480   <dt id="integer-resources-element"><code>&lt;resources&gt;</code></dt>
    481     <dd><strong>Required.</strong> This must be the root node.
    482       <p>No attributes.</p>
    483     </dd>
    484   <dt id="integer-element"><code>&lt;integer&gt;</code></dt>
    485     <dd>An integer.
    486       <p class="caps">attributes:</p>
    487       <dl class="atn-list">
    488         <dt><code>name</code></dt>
    489         <dd><em>String</em>. A name for the integer. This will be used as the resource ID.
    490         </dd>
    491       </dl>
    492     </dd>
    493 
    494 </dl>
    495 </dd> <!-- end  elements and attributes -->
    496 
    497 <dt>example:</dt>
    498 <dd>
    499   <p>XML file saved at <code>res/values/integers.xml</code>:</p>
    500 <pre>
    501 &lt;?xml version="1.0" encoding="utf-8"?>
    502 &lt;resources>
    503     &lt;integer name="max_speed">75&lt;/integer>
    504     &lt;integer name="min_speed">5&lt;/integer>
    505 &lt;/resources>
    506 </pre>
    507     <p>This application code retrieves an integer:</p>
    508 <pre>
    509 Resources res = {@link android.content.Context#getResources()};
    510 int maxSpeed = res.{@link android.content.res.Resources#getInteger(int) getInteger}(R.integer.max_speed);
    511 </pre>
    512 </dd> <!-- end example -->
    513 
    514 
    515 </dl>
    516 
    517 
    518 
    519 
    520 
    521 <h2 id="IntegerArray">Integer Array</h2>
    522 
    523 <p>An array of integers defined in XML.</p>
    524 
    525 <p class="note"><strong>Note:</strong> An integer array is a simple resource that is referenced
    526 using the value provided in the {@code name} attribute (not the name of the XML file). As
    527 such, you can combine integer array resources with other simple resources in the one XML file,
    528 under one {@code &lt;resources>} element.</p>
    529 
    530 
    531 <dl class="xml">
    532 
    533 <dt>file location:</dt>
    534 <dd><code>res/values/<em>filename</em>.xml</code><br/>
    535 The filename is arbitrary. The {@code &lt;integer-array>} element's {@code name} will be used as the
    536 resource ID.</dd>
    537 
    538 <dt>compiled resource datatype:</dt>
    539 <dd>Resource pointer to an array of integers.</dd>
    540 
    541 <dt>resource reference:</dt>
    542 <dd>
    543 In Java: <code>R.array.<em>integer_array_name</em></code><br/>
    544 In XML: <code>@[<em>package</em>:]array.<em>integer_array_name</em></code>
    545 </dd>
    546 
    547 <dt>syntax:</dt>
    548 <dd>
    549 <pre class="stx">
    550 &lt;?xml version="1.0" encoding="utf-8"?>
    551 &lt;<a href="#integer-array-resources-element">resources</a>>
    552     &lt;<a href="#integer-array-element">integer-array</a>
    553         name="<em>integer_array_name</em>">
    554         &lt;<a href="#integer-array-item-element">item</a>
    555             &gt;<em>integer</em>&lt;/item&gt;
    556     &lt;/integer-array>
    557 &lt;/resources>
    558 </pre>
    559 </dd>
    560 
    561 <dt>elements:</dt>
    562 <dd>
    563 <dl class="tag-list">
    564   <dt id="integer-array-resources-element"><code>&lt;resources&gt;</code></dt>
    565     <dd><strong>Required.</strong> This must be the root node.
    566       <p>No attributes.</p>
    567     </dd>
    568   <dt id="integer-array-element"><code>&lt;integer-array&gt;</code></dt>
    569     <dd>Defines an array of integers. Contains one or more child {@code &lt;item>} elements.
    570       <p class="caps">attributes:</p>
    571       <dl class="atn-list">
    572         <dt><code>android:name</code></dt>
    573         <dd><em>String</em>. A name for the array. This name will be used as the resource
    574 ID to reference the array.</dd>
    575       </dl>
    576     </dd>
    577   <dt id="integer-array-item-element"><code>&lt;item&gt;</code></dt>
    578     <dd>An integer. The value can be a reference to another
    579 integer resource. Must be a child of a {@code &lt;integer-array&gt;} element.
    580       <p>No attributes.</p>
    581     </dd>
    582 </dl>
    583 </dd> <!-- end  elements -->
    584 
    585 <dt>example:</dt>
    586 <dd>XML file saved at <code>res/values/integers.xml</code>:
    587 <pre>
    588 &lt;?xml version="1.0" encoding="utf-8"?>
    589 &lt;resources>
    590     &lt;integer-array name="bits">
    591         &lt;item>4&lt;/item>
    592         &lt;item>8&lt;/item>
    593         &lt;item>16&lt;/item>
    594         &lt;item>32&lt;/item>
    595     &lt;/integer-array>
    596 &lt;/resources>
    597 </pre>
    598 
    599   <p>This application code retrieves the integer array:</p>
    600 <pre>
    601 Resources res = {@link android.content.Context#getResources()};
    602 int[] bits = res.{@link android.content.res.Resources#getIntArray(int) getIntArray}(R.array.bits);
    603 </pre>
    604 </dd> <!-- end example -->
    605 
    606 </dl>
    607 
    608 
    609 
    610 
    611 
    612 <h2 id="TypedArray">Typed Array</h2>
    613 
    614 <p>A {@link android.content.res.TypedArray} defined in XML. You can use
    615 this to create an array of other resources, such as drawables. Note that the array
    616 is not required to be homogeneous, so you can create an array of mixed resource types, but
    617 you must be aware of what and where the data types are in the array so that you can properly obtain
    618 each item with the {@link android.content.res.TypedArray}'s {@code get...()} methods.</p>
    619 
    620 <p class="note"><strong>Note:</strong> A typed array is a simple resource that is referenced
    621 using the value provided in the {@code name} attribute (not the name of the XML file). As
    622 such, you can combine typed array resources with other simple resources in the one XML file,
    623 under one {@code &lt;resources&gt;} element.</p>
    624 
    625 
    626 <dl class="xml">
    627 
    628 <dt>file location:</dt>
    629 <dd><code>res/values/<em>filename</em>.xml</code><br/>
    630 The filename is arbitrary. The {@code &lt;array>} element's {@code name} will be used as the
    631 resource ID.</dd>
    632 
    633 <dt>compiled resource datatype:</dt>
    634 <dd>Resource pointer to a {@link android.content.res.TypedArray}.</dd>
    635 
    636 <dt>resource reference:</dt>
    637 <dd>
    638 In Java: <code>R.array.<em>array_name</em></code><br/>
    639 In XML: <code>@[<em>package</em>:]array.<em>array_name</em></code>
    640 </dd>
    641 
    642 <dt>syntax:</dt>
    643 <dd>
    644 <pre class="stx">
    645 &lt;?xml version="1.0" encoding="utf-8"?>
    646 &lt;<a href="#array-resources-element">resources</a>>
    647     &lt;<a href="#array-element">array</a>
    648         name="<em>integer_array_name</em>">
    649         &lt;<a href="#array-item-element">item</a>&gt;<em>resource</em>&lt;/item&gt;
    650     &lt;/array>
    651 &lt;/resources>
    652 </pre>
    653 </dd>
    654 
    655 <dt>elements:</dt>
    656 <dd>
    657 <dl class="tag-list">
    658   <dt id="array-resources-element"><code>&lt;resources&gt;</code></dt>
    659     <dd><strong>Required.</strong> This must be the root node.
    660       <p>No attributes.</p>
    661     </dd>
    662   <dt id="array-element"><code>&lt;array&gt;</code></dt>
    663     <dd>Defines an array. Contains one or more child {@code &lt;item>} elements.
    664       <p class="caps">attributes:</p>
    665       <dl class="atn-list">
    666         <dt><code>android:name</code></dt>
    667         <dd><em>String</em>. A name for the array. This name will be used as the resource
    668 ID to reference the array.</dd>
    669       </dl>
    670     </dd>
    671   <dt id="array-item-element"><code>&lt;item&gt;</code></dt>
    672     <dd>A generic resource. The value can be a reference to a resource or a simple data type.
    673 Must be a child of an {@code &lt;array&gt;} element.
    674       <p>No attributes.</p>
    675     </dd>
    676 </dl>
    677 </dd> <!-- end  elements -->
    678 
    679 <dt>example:</dt>
    680 <dd>XML file saved at <code>res/values/arrays.xml</code>:
    681 <pre>
    682 &lt;?xml version="1.0" encoding="utf-8"?>
    683 &lt;resources>
    684     &lt;array name="icons">
    685         &lt;item>@drawable/home&lt;/item>
    686         &lt;item>@drawable/settings&lt;/item>
    687         &lt;item>@drawable/logout&lt;/item>
    688     &lt;/array>
    689     &lt;array name="colors">
    690         &lt;item>#FFFF0000&lt;/item>
    691         &lt;item>#FF00FF00&lt;/item>
    692         &lt;item>#FF0000FF&lt;/item>
    693     &lt;/array>
    694 &lt;/resources>
    695 </pre>
    696 
    697   <p>This application code retrieves each array and then obtains the first entry in each array:</p>
    698 <pre>
    699 Resources res = {@link android.content.Context#getResources()};
    700 TypedArray icons = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.icons);
    701 Drawable drawable = icons.{@link android.content.res.TypedArray#getDrawable(int) getDrawable}(0);
    702 
    703 TypedArray colors = res.{@link android.content.res.Resources#obtainTypedArray(int) obtainTypedArray}(R.array.colors);
    704 int color = colors.{@link android.content.res.TypedArray#getColor(int,int) getColor}(0,0);
    705 </pre>
    706 </dd> <!-- end example -->
    707 
    708 </dl>
    709 
    710 
    711 
    712 
    713 
    714 
    715 
    716 
    717 
    718 
    719 <!-- TODO
    720 
    721 
    722 <h2>Styleable Attribute</h2>
    723 
    724 
    725 <dl class="xml">
    726 
    727 <dt>syntax:</dt>
    728 <dd>
    729 <pre class="stx">
    730 </pre>
    731 </dd>
    732 
    733 <dt>file location:</dt>
    734 <dd><code>res/</code></dd>
    735 
    736 <dt>compiled resource datatype:</dt>
    737 <dd>Resource pointer to a {@link android.view.Menu} (or subclass) resource.</dd>
    738 
    739 <dt>resource reference:</dt>
    740 <dd>Java: <code>R.</code><br/>
    741     XML:
    742 </dd>
    743 
    744 <dt>elements and attributes:</dt>
    745 <dd>
    746 <dl class="attr">
    747 
    748   <dt><code></code></dt>
    749     <dd></dd>
    750   <dt><code></code></dt>
    751     <dd>Valid attributes:
    752       <dl>
    753         <dt><code></code></dt>
    754         <dd>
    755         </dd>
    756         <dt><code></code></dt>
    757         <dd>
    758         </dd>
    759       </dl>
    760     </dd>
    761 
    762 </dl>
    763 </dd> 
    764 
    765 <dt>example:</dt>
    766 <dd>
    767   <dl>
    768 
    769     <dt>XML file saved at <code>res/</code>:</dt>
    770     <dd>
    771 <pre>
    772 
    773 </pre>
    774     </dd>
    775 
    776     <dt>Java code :</dt>
    777     <dd>
    778 <pre>
    779 
    780 </pre>
    781     </dd>
    782 
    783   </dl>
    784 </dd> 
    785 
    786 
    787 <dt>see also:</dt>
    788 <dd>
    789 <ul>
    790   <li></li>
    791 </ul>
    792 </dd>
    793 
    794 </dl>
    795 
    796 
    797 
    798 
    799 
    800 
    801 -->
    802 
    803 
    804 
    805 
    806