<li>{@link android.R.style} for Android styles and themes</li>
<li>{@link android.R.attr} for all style attributes</li>
</ol>
</div>
</div>
<p>When designing your application, you can use <em>styles</em> and <em>themes</em> to apply uniform formatting to its various screens and UI elements.
<ul>
<li>A style is a set of one or more formatting attributes that you can apply as a unit to single elements in your layout XML file(s). For example, you could define a style that specifies a certain text size and color, then apply it to instances of a certain type of View element.</li>
<li>A theme is a set of one or more formatting attributes that you can apply as a unit to all activities in an application or just a single activity. For example, you could define a theme that sets specific colors for the window frame and the panel foreground and background, and sets text sizes and colors for menus, then apply it to the activities of your application.</li>
</ul>
<p>A <strong>style</strong> is a collection of properties that
specify the look and format for a {@link android.view.View} or window.
A style can specify properties such as height, padding, font color, font size,
background color, and much more. A style is defined in an XML resource that is
separate from the XML that specifies the layout.</p>
<p>Styles and themes are resources. Android provides some default style and theme resources that you can use, or you can declare your own custom style and theme resources.</p>
<p>Styles in Android share a similar philosophy to cascading stylesheets in web
design—they allow you to separate the design from the
content.</p>
<p>To create custom styles and themes:</p>
<ol>
<li>Create a file named <code>styles.xml</code> in the your application's <code>res/values</code> directory. Add a root <code><resources></code> node.</li>
<li>For each style or theme, add a <code><style></code> element with a unique <code>name</code> and, optionally, a <code>parent</code> attribute.
The name is used for referencing these styles later, and the parent indicates what style resource to inherit from.</li>
<li>Inside the <code><style></code> element, declare format values in one or more <code><item></code> element(s).
Each <code><item></code> identifies its style property with a <code>name</code> attribute and defines its style value inside the element.</li>
<li>You can then reference the custom resources from other XML resources, your manifest or application code.</li>
</ol>
<p>For example, by using a style, you can take this layout XML:</p>
<pre>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />
</pre>
<p>And turn it into this:</p>
<pre>
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
</pre>
<p>All of the attributes related to style have been removed from the layout XML and put into a
style definition called {@code CodeFont}, which is then applied with the <code>style</code>
attribute. You'll see the definition for this style in the following section.</p>
<p>A <strong>theme</strong> is a style applied to an entire {@link android.app.Activity} or
application, rather than an individual {@link android.view.View} (as in the example above). When a
style is applied as a theme, every View in the Activity or application will apply each style
property that it supports. For example, you can apply the same {@code CodeFont} style
as a theme for an Activity and then all text inside that Activity will have green monospace
font.</p>
<h2 id="styles">Styles</h2>
<h2 id="DefiningStyles">Defining Styles</h2>
<p>Here's an example declaration of a style: </p>
<p>To create a set of styles, save an XML file in the {@code res/values/}
directory of your project. The name of the XML file is arbitrary, but it must use the
{@code .xml} extension and be saved in the {@code res/values/} folder.</p>
<p>The root node of the XML file must be {@code <resources>}.</p>
<p>For each style you want to create, add a {@code <style>} element to the file
with a {@code name} that uniquely identifies the style (this attribute is required).
Then add an {@code <item>} element for each property of that style, with a
{@code name} that declares the style property and a value to go with it (this attribute
is required). The value for the {@code <item>} can
be a keyword string, a hex color, a reference to another resource type, or other value
<p>As shown, you can use <code><item></code> elements to set specific formatting values for the style.
The <code>name</code> attribute in the <code>item</code> can refer to a standard string, a hex color value,
or a reference to any other resource type.</p>
<p>Each child of the {@code <resources>} element is converted into an application resource
object at compile-time, which can be referenced by the value in the {@code <style>} element's
{@code name} attribute. This example style can be referenced from an XML layout as
{@code @style/CodeFont} (as demonstrated in the introduction above).</p>
<p>The <code>parent</code> attribute in the {@code <style>} element is optional and
specifies the resource ID of another style from which this style should inherit
properties. You can then override the inherited style properties if you want to.</p>
<p>Remember, a style that you want to use as an Activity or application theme is defined in XML
exactly the same as a style for a View. A style such as the one defined above can be applied as a
style for a single View or as a theme for an entire Activity or application. How to apply a style
for a single View or as an application theme is discussed later.</p>
<p>Notice the <code>parent</code> attribute in the <code><style></code> element. This attribute lets you specify a resource from which the current style will inherit values. The style can inherit from any type of resource that contains the style(s) you want. In general, your styles should always inherit (directly or indirectly) from a standard Android style resource. This way, you only have to define the values that you want to change.</p>
<h3 id="Inheritance">Inheritance</h3>
<p>Here's how you would reference the custom style from an XML layout, in this case, for an EditText element:</p>
<p>The {@code parent} attribute in the {@code <style>} element lets you specify a style
from which your style should inherit properties.
You can use this to inherit properties from an existing style and
then define only the properties that you want to change or add. You can
inherit from styles that you've created yourself or from styles that are built into the
platform. (See <a href="#PlatformStyles">Using Platform Styles and Themes</a>, below, for
information about inheriting from styles defined by the Android platform.) For example, you can
inherit the Android platform's default text appearance and then modify it:</p>