1 page.title=Style Resource 2 parent.title=Resource Types 3 parent.link=available-resources.html 4 @jd:body 5 6 <div id="qv-wrapper"> 7 <div id="qv"> 8 <h2>See also</h2> 9 <ol> 10 <li><a href="{@docRoot}guide/topics/ui/themes.html">Styles and Themes</a></li> 11 </ol> 12 </div> 13 </div> 14 15 16 <p>A style resource defines the format and look for a UI. 17 A style can be applied to an individual {@link android.view.View} (from within a layout file) or to 18 an entire {@link android.app.Activity} or application (from within the manifest file).</p> 19 20 <p>For more information about creating and applying styles, please read 21 <a href="{@docRoot}guide/topics/ui/themes.html">Styles and Themes</a>.</p> 22 23 <p class="note"><strong>Note:</strong> A style is a simple resource that is referenced 24 using the value provided in the {@code name} attribute (not the name of the XML file). As 25 such, you can combine style resources with other simple resources in the one XML file, 26 under one {@code <resources>} element.</p> 27 28 <dl class="xml"> 29 30 <dt>file location:</dt> 31 <dd><code>res/values/<em>filename</em>.xml</code><br/> 32 The filename is arbitrary. The element's {@code name} will be used as the resource ID.</dd> 33 34 <dt>resource reference:</dt> 35 <dd> 36 In XML: <code>@[package:]style/<em>style_name</em></code> 37 </dd> 38 39 <dt>syntax:</dt> 40 <dd> 41 <pre class="stx"> 42 <?xml version="1.0" encoding="utf-8"?> 43 <<a href="#resources-element">resources</a>> 44 <<a href="#style-element">style</a> 45 name="<em>style_name</em>" 46 parent="@[package:]style/<em>style_to_inherit</em>"> 47 <<a href="#item-element">item</a> 48 name="<em>[package:]style_property_name</em>" 49 ><em>style_value</em></item> 50 </style> 51 </resources> 52 </pre> 53 </dd> 54 55 <dt>elements:</dt> 56 <dd> 57 <dl class="tag-list"> 58 59 <dt id="resources-element"><code><resources></code></dt> 60 <dd><strong>Required.</strong> This must be the root node. 61 <p>No attributes.</p> 62 </dd> 63 <dt id="style-element"><code><style></code></dt> 64 <dd>Defines a single style. Contains {@code <item>} elements. 65 <p class="caps">attributes:</p> 66 <dl class="atn-list"> 67 <dt><code>name</code></dt> 68 <dd><em>String</em>. <strong>Required</strong>. A name for the style, which is used as the 69 resource ID to apply the style to a View, Activity, or application. 70 </dd> 71 <dt><code>parent</code></dt> 72 <dd><em>Style resource</em>. Reference to a style from which this 73 style should inherit style properties. 74 </dd> 75 </dl> 76 77 </dd> 78 <dt id="item-element"><code><item></code></dt> 79 <dd>Defines a single property for the style. Must be a child of a 80 <code><style></code> element.</p> 81 <p class="caps">attributes:</p> 82 <dl class="atn-list"> 83 <dt><code>name</code></dt> 84 <dd><em>Attribute resource</em>. <strong>Required</strong>. The name of the style property 85 to be defined, with a package prefix if necessary (for example {@code android:textColor}). 86 </dd> 87 </dl> 88 </dd> 89 90 </dl> 91 </dd> <!-- end elements and attributes --> 92 93 <dt>example:</dt> 94 <dd> 95 <dl> 96 97 <dt>XML file for the style (saved in <code>res/values/</code>):</dt> 98 <dd> 99 <pre> 100 <?xml version="1.0" encoding="utf-8"?> 101 <resources> 102 <style name="CustomText" parent="@style/Text"> 103 <item name="android:textSize">20sp</item> 104 <item name="android:textColor">#008</item> 105 </style> 106 </resources> 107 </pre> 108 </dd> 109 110 <dt>XML file that applies the style to a {@link android.widget.TextView} 111 (saved in <code>res/layout/</code>):</dt> 112 <dd> 113 <pre> 114 <?xml version="1.0" encoding="utf-8"?> 115 <EditText 116 style="@style/CustomText" 117 android:layout_width="fill_parent" 118 android:layout_height="wrap_content" 119 android:text="Hello, World!" /> 120 </pre> 121 </dd> 122 123 </dl> 124 </dd> <!-- end example --> 125 126 </dl> 127 128 129