1b10b48f62d3cac684424e4181d4e8ec61f227e95Scott Mainpage.title=Styles and Themes
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectparent.title=User Interface
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectparent.link=index.html
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project@jd:body
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<div id="qv-wrapper">
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<div id="qv">
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <h2>In this document</h2>
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <ol>
104d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li><a href="#DefiningStyles">Defining Styles</a>
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      <ol>
124d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        <li><a href="#Inheritance">Inheritance</a></li>
134d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        <li><a href="#Properties">Style Properties</a></li>
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      </ol>
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    </li>
164d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li><a href="#ApplyingStyles">Applying Styles and Themes to the UI</a>
174d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main      <ol>
184d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        <li><a href="#ApplyAStyle">Apply a style to a View</a></li>
194d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        <li><a href="#ApplyATheme">Apply a theme to an Activity or application</a></li>
20ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn        <li><a href="#SelectATheme">Select a theme based on platform version</a></li>
214d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main      </ol>
224d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    </li>
234d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li><a href="#PlatformStyles">Using Platform Styles and Themes</a></li>
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  </ol>
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <h2>See also</h2>
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <ol>
274d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li><a href="{@docRoot}guide/topics/resources/available-resources.html#stylesandthemes">Style
284d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    and Theme Resources</a></li>
294d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li>{@link android.R.style} for Android styles and themes</li>
304d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    <li>{@link android.R.attr} for all style attributes</li>
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  </ol>
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</div>
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</div>
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
364d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>A <strong>style</strong> is a collection of properties that
374d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainspecify the look and format for a {@link android.view.View} or window.
384d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainA style can specify properties such as height, padding, font color, font size,
394d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainbackground color, and much more. A style is defined in an XML resource that is
404d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainseparate from the XML that specifies the layout.</p>
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
424d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Styles in Android share a similar philosophy to cascading stylesheets in web
434d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maindesign&mdash;they allow you to separate the design from the
444d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maincontent.</p>
454d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
464d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>For example, by using a style, you can take this layout XML:</p>
474d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
484d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;TextView
494d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:layout_width="fill_parent"
504d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:layout_height="wrap_content"
514d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:textColor="#00FF00"
524d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:typeface="monospace"
534d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:text="@string/hello" />
544d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
554d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>And turn it into this:</p>
564d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
574d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;TextView
584d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    style="@style/CodeFont"
594d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:text="@string/hello" />
604d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
624d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>All of the attributes related to style have been removed from the layout XML and put into a
634d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle definition called {@code CodeFont}, which is then applied with the <code>style</code>
644d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainattribute. You'll see the definition for this style in the following section.</p>
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
664d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>A <strong>theme</strong> is a style applied to an entire {@link android.app.Activity} or
674d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainapplication, rather than an individual {@link android.view.View} (as in the example above). When a
684d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle is applied as a theme, every View in the Activity or application will apply each style
694d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainproperty that it supports. For example, you can apply the same {@code CodeFont} style
704d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainas a theme for an Activity and then all text inside that Activity will have green monospace
714d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainfont.</p>
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
744d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h2 id="DefiningStyles">Defining Styles</h2>
754d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
764d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>To create a set of styles, save an XML file in the {@code res/values/}
774d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maindirectory of your project. The name of the XML file is arbitrary, but it must use the
784d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code .xml} extension and be saved in the {@code res/values/} folder.</p>
794d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
804d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The root node of the XML file must be {@code &lt;resources&gt;}.</p>
814d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
824d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>For each style you want to create, add a {@code &lt;style>} element to the file
834d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainwith a {@code name} that uniquely identifies the style (this attribute is required).
844d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainThen add an {@code &lt;item>} element for each property of that style, with a
854d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code name} that declares the style property and a value to go with it (this attribute
864d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainis required). The value for the {@code &lt;item>} can
874d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainbe a keyword string, a hex color, a reference to another resource type, or other value
884d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maindepending on the style property.
894d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainHere's an example file with a single style:</p>
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
924d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;?xml version="1.0" encoding="utf-8"?>
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project&lt;resources&gt;
944d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;style name="CodeFont" parent="@android:style/TextAppearance.Medium"&gt;
954d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:layout_width"&gt;fill_parent&lt;/item&gt;
964d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt;
974d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:textColor"&gt;#00FF00&lt;/item&gt;
984d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:typeface"&gt;monospace&lt;/item&gt;
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    &lt;/style&gt;
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project&lt;/resources&gt;
1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1034d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Each child of the {@code &lt;resources>} element is converted into an application resource
1044d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainobject at compile-time, which can be referenced by the value in the {@code &lt;style>} element's
1054d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code name} attribute. This example style can be referenced from an XML layout as
1064d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code @style/CodeFont} (as demonstrated in the introduction above).</p>
1074d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1084d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The <code>parent</code> attribute in the {@code &lt;style>} element is optional and
1094d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainspecifies the resource ID of another style from which this style should inherit
1104d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainproperties. You can then override the inherited style properties if you want to.</p>
1114d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1124d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Remember, a style that you want to use as an Activity or application theme is defined in XML
1134d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainexactly the same as a style for a View. A style such as the one defined above can be applied as a
1144d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle for a single View or as a theme for an entire Activity or application. How to apply a style
1154d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainfor a single View or as an application theme is discussed later.</p>
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1184d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h3 id="Inheritance">Inheritance</h3>
1194d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1204d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The {@code parent} attribute in the {@code &lt;style>} element lets you specify a style
1214d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainfrom which your style should inherit properties.
1224d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainYou can use this to inherit properties from an existing style and
1234d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthen define only the properties that you want to change or add. You can
1244d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maininherit from styles that you've created yourself or from styles that are built into the
1254d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainplatform. (See <a href="#PlatformStyles">Using Platform Styles and Themes</a>, below, for
1264d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maininformation about inheriting from styles defined by the Android platform.) For example, you can
1274d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maininherit the Android platform's default text appearance and then modify it:</p>
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
1304d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;style name="GreenText" parent="@android:style/TextAppearance"&gt;
1314d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:textColor"&gt;#00FF00&lt;/item&gt;
1324d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;/style&gt;
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1354d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>If you want to inherit from styles that you've defined yourself, you <em>do not</em> have to use
1364d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthe <code>parent</code> attribute. Instead, just prefix the name of the style you want to
1374d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maininherit to the name of your new style, separated by a period. For example, to create a new style
1384d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthat inherits the <code>CodeFont</code> style defined above, but make the color red,
1394d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainyou can author the new style like this:</p>
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1414d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
1424d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;style name="CodeFont.Red"&gt;
1434d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:textColor"&gt;#FF0000&lt;/item&gt;
1444d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;/style&gt;
1454d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
1464d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1474d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Notice that there is no {@code parent} attribute in the {@code &lt;style&gt;} tag, but because
1484d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthe {@code name} attribute begins with the {@code CodeFont} style name (which
1494d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainis a style that you have created), this style inherits all style properties from that style. This
1504d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle then overrides the {@code android:textColor} property to make the text red. You can
1514d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainreference this new style as {@code @style/CodeFont.Red}.</p>
1524d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1534d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>You can continue inheriting like
1544d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthis as many times as you'd like, by chaining names with periods. For example, you can
1554d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainextend {@code CodeFont.Red} to be bigger, with:</p>
1564d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
1574d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;style name="CodeFont.Red.Big"&gt;
1584d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main        &lt;item name="android:textSize"&gt;30sp&lt;/item&gt;
1594d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    &lt;/style&gt;
1604d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
1614d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>This inherits from both {@code CodeFont} and {@code CodeFont.Red} styles, then adds the
1624d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code android:textSize} property.</p>
1634d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1644d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p class="note"><strong>Note:</strong> This technique for inheritance by chaining together
1654d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainnames only works for styles defined by your own resources. You can't inherit Android built-in styles
1664d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthis way. To reference a built-in style, such as {@link android.R.style#TextAppearance}, you must
1674d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainuse the {@code parent} attribute.</p>
1684d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1694d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1704d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h3 id="Properties">Style Properties</h3>
1714d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1724d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Now that you understand how a style is defined, you need to learn what kind
1734d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainof style properties&mdash;defined by the {@code &lt;item>} element&mdash;are available.
1744d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainYou're probably familiar with some already, such as {@link android.R.attr#layout_width} and
1754d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@link android.R.attr#textColor}. Of course, there are many more style properties you can use.</p>
1764d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1774d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The best place to find properties that apply to a specific {@link android.view.View} is the
1784d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maincorresponding class reference, which lists all of the supported XML attributes. For example, all of the
1794d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainattributes listed in the table of
1804d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<a href="{@docRoot}reference/android/widget/TextView.html#lattrs">TextView XML 
1814d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainattributes</a> can be used in a style definition for a {@link android.widget.TextView} element (or one of
1824d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainits subclasses). One of the attributes listed in the reference is <a
1834d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainhref="{@docRoot}reference/android/widget/TextView.html#attr_android:inputType">{@code
1844d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainandroid:inputType}</a>, so where you might normally place the <a
1854d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainhref="{@docRoot}reference/android/widget/TextView.html#attr_android:inputType">{@code
1864d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainandroid:inputType}</a>
1874d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainattribute in an {@code &lt;EditText>} element, like this:</p>
1884d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
1894d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;EditText
1904d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:inputType="number"
1914d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    ... />
1924d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
1934d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
1944d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>You can instead create a style for the {@link android.widget.EditText} element that includes this property:</p>
1954d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
1964d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;style name="Numbers">
1974d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  &lt;item name="android:inputType">number&lt;/item>
1984d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  ...
1994d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;/style>
2004d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
2014d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>So your XML for the layout can now implement this style:</p>
2024d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
2034d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;EditText
2044d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    style="@style/Numbers"
2054d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    ... />
2064d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
2074d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2084d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>This simple example may look like more work, but when you add more style properties and
2094d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainfactor-in the ability to re-use the style in various places, the pay-off can be huge.</p>
2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2114d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>For a reference of all available style properties, see the {@link android.R.attr}
2124d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainreference. Keep in mind that all View objects don't accept all the same style attributes, so you
2134d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainshould normally refer to the specific {@link android.view.View} class for supported style
2144d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainproperties. However, if you
2154d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainapply a style to a View that does not support all of the style properties, the View will
2164d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainapply only those properties that are supported and simply ignore the others.</p>
2179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2184d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Some style properties, however, are not supported by any View element and can only be applied
2194d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainas a theme. These style properties apply to the entire window and not to any type of View.
2204d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainFor example, style properties for a theme can hide the application title, hide the status bar,
2214d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainor change the window's background. These kind of style properties do not belong to any View object.
2224d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainTo discover these theme-only style properties, look at the {@link android.R.attr} reference for
2234d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainattributes that begin with {@code window}. For instance, {@code windowNoTitle} and {@code
2244d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainwindowBackground} are style properties that are effective only when the style is applied as
2254d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maina theme to an Activity or application. See the next section for information about applying a
2264d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle as a theme.</p>
2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2284d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p class="note"><strong>Note:</strong> Don't forget to prefix the property names in each
2294d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code &lt;item&gt;} element with the <code>android:</code> namespace. For example:
2304d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code &lt;item name="android:inputType">}.</p>
2314d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2324d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2334d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2344d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h2 id="ApplyingStyles">Applying Styles and Themes to the UI</h2>
2354d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2364d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>There are two ways to set a style:</p>
2374d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<ul>
2384d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  <li>To an individual View, by adding the <code>style</code> attribute to a View
2394d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  element in the XML for your layout.</li>
2404d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  <li>Or, to an entire Activity or application, by adding the <code>android:theme</code>
2414d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  attribute to the <code>&lt;activity></code> or <code>&lt;application></code> element
2424d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main  in the Android manifest.</li>
2434d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</ul>
2444d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2454d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>When you apply a style to a single {@link android.view.View} in the layout, the properties
2464d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maindefined by the style are applied only to that {@link android.view.View}. If a style is applied to a
2474d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@link android.view.ViewGroup}, the child {@link android.view.View} elements will
2484d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<strong>not</strong> inherit the style properties&mdash;only the element to which you directly apply
2494d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthe style will apply its properties. However, you <em>can</em> apply a style so that it
2504d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainapplies to all {@link android.view.View} elements&mdash;by applying the style as a theme.</p>
2514d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2524d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>To apply a style definition as a theme, you must apply the style to an
2534d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@link android.app.Activity} or application in the Android manifest. When you do so,
2544d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainevery {@link android.view.View} within the Activity or
2554d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainapplication will apply each property that it supports. For example, if you apply the {@code
2564d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainCodeFont} style from the previous examples to an Activity, then all View elements
2574d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthat support the text style properties will apply them. Any View that does not support
2584d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthe properties will ignore them. If a View supports only some of the properties, then
2594d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainit will apply only those properties.</p>
2604d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2614d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2624d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h3 id="ApplyAStyle">Apply a style to a View</h3>
2634d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2644d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Here's how to set a style for a View in the XML layout:</p>
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
2674d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;TextView
2684d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    style="@style/CodeFont"
2694d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main    android:text="@string/hello" />
2704d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
2714d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2724d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Now this TextView will be styled as defined by the style named {@code CodeFont}.
2734d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main(See the sample above, in <a href="#DefiningStyles">Defining Styles</a>.)</p>
2744d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2754d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p class="note"><strong>Note:</strong> The <code>style</code> attribute
2764d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Maindoes <em>not</em> use the <code>android:</code> namespace prefix.</p>
2774d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2784d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2794d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h3 id="ApplyATheme">Apply a theme to an Activity or application</h3>
2804d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
2814d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>To set a theme for all the activities of your application, open the {@code AndroidManifest.xml} file and
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectedit the <code>&lt;application></code> tag to include the <code>android:theme</code> attribute with the 
2834d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainstyle name. For example:</p>
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project&lt;application android:theme="@style/CustomTheme">
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2894d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>If you want a theme applied to just one Activity in your application, then add the 
2904d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<code>android:theme</code> attribute to the <code>&lt;activity></code> tag instead.</p>
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2924d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Just as Android provides other built-in resources, there are many pre-defined themes that you can use, to avoid
2934d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainwriting them yourself. For example, you can use the {@code Dialog} theme and make your Activity
2944d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainappear like a dialog box:</p>
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project&lt;activity android:theme="@android:style/Theme.Dialog">
2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3004d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>Or if you want the background to be transparent, use the Translucent theme:</p>
3014d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3024d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
3034d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;activity android:theme="@android:style/Theme.Translucent">
3044d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
3054d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3064d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>If you like a theme, but want to tweak it, just add the theme as the <code>parent</code>
307ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackbornof your custom theme. For example, you can modify the traditional light theme to use your own
308ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborncolor like this:</p>
3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
310ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;color name="custom_theme_color">#b0b0ff&lt;/color>
311ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;style name="CustomTheme" parent="android:Theme.Light">
312ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn    &lt;item name="android:windowBackground">@color/custom_theme_color&lt;/item>
313ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn    &lt;item name="android:colorBackground">@color/custom_theme_color&lt;/item>
3144d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main&lt;/style>
3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
317ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>(Note that the color needs to supplied as a separate resource here because
318ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackbornthe <code>android:windowBackground</code> attribute only supports a reference to
319ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackbornanother resource; unlike <code>android:colorBackground</code>, it can not be given
320ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborna color literal.)</p>
321ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
322ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>Now use {@code CustomTheme} instead of {@code Theme.Light} inside the Android
3234d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainManifest:</p>
3244d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3254d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<pre>
326ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;activity android:theme="@style/CustomTheme">
327ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn</pre>
328ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
329f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main
330ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<h3 id="SelectATheme">Select a theme based on platform version</h3>
331ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
332ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>Newer versions of Android have additional themes available to applications,
333f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainand you might want to use these while running on those platforms while still being
334ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborncompatible with older versions.  You can accomplish this through a custom theme
335f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainthat uses resource selection to switch between different parent themes, based on the platform
336f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainversion.</p>
337ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
338ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>For example, here is the declaration for a custom theme which is simply
339ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackbornthe standard platforms default light theme.  It would go in an XML file under
340ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<code>res/values</code> (typically <code>res/values/styles.xml</code>):
341ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<pre>
342ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;style name="LightThemeSelector" parent="android:Theme.Light">
343f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main    ...
344ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;/style>
345ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn</pre>
346ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
347f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main<p>To have this theme use the newer holographic theme when the application is running
348f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainon Android 3.0 (API Level 11) or higher, you can place an alternative
349f1d8e04912b6a4031e0d1f129c231de869852a04Scott Maindeclaration for the theme in an XML file in <code>res/values-v11</code>, but make the parent theme
350f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainthe holographic theme:</p>
351ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<pre>
352ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;style name="LightThemeSelector" parent="android:Theme.Holo.Light">
353f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main    ...
354ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn&lt;/style>
3554d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</pre>
3564d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
357ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>Now use this theme like you would any other, and your application will
358f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainautomatically switch to the holographic theme if running on Android 3.0 or higher.</p>
359ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn
360ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackborn<p>A list of the standard attributes that you can use in themes can be
361ae91b5ac7d18e4e461fa42709f51da73d29c403aDianne Hackbornfound at {@link android.R.styleable#Theme R.styleable.Theme}.</p>
3624d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
363f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main<p>For more information about providing alternative resources, such as themes and layouts, based
364f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainon the platform version or other device configurations, see the <a
365f1d8e04912b6a4031e0d1f129c231de869852a04Scott Mainhref="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resources</a>
366f1d8e04912b6a4031e0d1f129c231de869852a04Scott Maindocument.</p>
367f1d8e04912b6a4031e0d1f129c231de869852a04Scott Main
3684d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<!-- This currently has some bugs
3694d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3704d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h3 id="setThemeFromTheApp">Set the theme from the application</h3>
3714d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3724d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>We recommend that you set your themes in you Android manifest, as described above, because it's simple and
3734d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainkeeps your program code focused on application functionality, rather than style. But if it's necessary
3744d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainfor you to change your theme programatically (perhaps based on a user preference), you can.</p>
3754d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
3764d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>To set the theme in your program code, use the {@link android.content.ContextWrapper#setTheme(int)}
3774d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainmethod and pass it the theme resource ID. Note that, when doing so, you must be sure to set the theme <em>before</em> 
3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectinstantiating any Views in the context, for example, before calling 
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<code>setContentView(View)</code> or <code>inflate(int, ViewGroup)</code>. This ensures that 
3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectthe system applies the same theme for all of your UI screens. Here's an example:</p>
3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void onCreate(Bundle savedInstanceState) {
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    super.onCreate(savedInstanceState);
3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    ...
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    setTheme(android.R.style.Theme_Light);
3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    setContentView(R.layout.linear_layout_3);
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<p>If you are considering loading a theme programmatically for the main
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectscreen of your application, note that the theme would not be applied
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectin any animations the system would use to start the activity, which
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectwould take place before your application opens. In most cases, if 
3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectyou want to apply a theme to your main screen, doing so in XML
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project is a better approach. </p>
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3984d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main-->
3994d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4004d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4014d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4024d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<h2 id="PlatformStyles">Using Platform Styles and Themes</h2>
4034d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4044d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The Android platform provides a large collection of styles and themes that you can
4054d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainuse in your applications. You can find a reference of all available styles in the
4064d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@link android.R.style} class. To use the styles listed here, replace all underscores in
4074d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthe style name with a period. For example, you can apply the
4084d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@link android.R.style#Theme_NoTitleBar} theme with
4094d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main{@code "@android:style/Theme.NoTitleBar"}.</p>
4104d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4114d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>The {@link android.R.style} reference, however, is not well documented and does not
4124d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthoroughly describe the styles, so viewing the actual source code for these styles and
4134d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainthemes will give you a better understanding of what style properties each one provides.
4144d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainFor a better reference to the Android styles and themes, see the following source code:</p>
4154d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<ul>
416600a75c31f0bb0993b815a17b7e22263f9ffb3b3Scott Main	<li><a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml">Android Styles (styles.xml)</a></li>
417600a75c31f0bb0993b815a17b7e22263f9ffb3b3Scott Main	<li><a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml">Android Themes (themes.xml)</a></li>
4184d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main</ul>
4194d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
4204d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>These files will help you learn through example. For instance, in the Android themes source code,
4214d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainyou'll find a declaration for <code>&lt;style name="Theme.Dialog"&gt;</code>. In this definition,
4224d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainyou'll see all of the properties that are used to style dialogs that are used by the Android
4234d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Mainframework.</p>
4244d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main
425816518fa595913edb1b9104d50907a9b97321ec2Scott Main<p>For more information about the syntax for styles and themes in XML, see the
426816518fa595913edb1b9104d50907a9b97321ec2Scott Main<a href="{@docRoot}guide/topics/resources/style-resource.html">Style Resource</a> document.</p>
4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4284d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main<p>For a reference of available style attributes that you can use to define a style or theme
4294d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott Main(e.g., "windowBackground" or "textAppearance"), see {@link android.R.attr} or the respective
4304d5770904c6b1a20c46fc25ccb00bdd34d5e3386Scott MainView class for which you are creating a style.</p>
4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
436