page.title=Styles and Themes parent.title=User Interface parent.link=index.html @jd:body

In this document

  1. Defining Styles
    1. Inheritance
    2. Style Properties
  2. Applying Styles and Themes to the UI
    1. Apply a style to a View
    2. Apply a theme to an Activity or application
    3. Select a theme based on platform version
  3. Using Platform Styles and Themes

See also

  1. Style and Theme Resources
  2. {@link android.R.style} for Android styles and themes
  3. {@link android.R.attr} for all style attributes

A style 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.

Styles in Android share a similar philosophy to cascading stylesheets in web design—they allow you to separate the design from the content.

For example, by using a style, you can take this layout XML:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />

And turn it into this:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

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 style attribute. You'll see the definition for this style in the following section.

A theme 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.

Defining Styles

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.

The root node of the XML file must be {@code }.

For each style you want to create, add a {@code