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