From ae91b5ac7d18e4e461fa42709f51da73d29c403a Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Sun, 16 Jan 2011 14:25:57 -0800 Subject: [PATCH] Update theme documentation a bit. Change-Id: I3dbb2785973fe2618033a3956b99f1100a46b054 --- docs/html/guide/topics/ui/themes.jd | 49 +++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/docs/html/guide/topics/ui/themes.jd b/docs/html/guide/topics/ui/themes.jd index de699f23297c6..57c9f2e32c067 100644 --- a/docs/html/guide/topics/ui/themes.jd +++ b/docs/html/guide/topics/ui/themes.jd @@ -17,6 +17,7 @@ parent.link=index.html
  1. Apply a style to a View
  2. Apply a theme to an Activity or application
  3. +
  4. Select a theme based on platform version
  • Using Platform Styles and Themes
  • @@ -303,21 +304,57 @@ appear like a dialog box:

    If you like a theme, but want to tweak it, just add the theme as the parent -of your custom theme. For example, you can modify the traditional dialog theme to use your own -background image like this:

    +of your custom theme. For example, you can modify the traditional light theme to use your own +color like this:

    -<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
    -    <item name="android:windowBackground">@drawable/custom_dialog_background</item>
    +<color name="custom_theme_color">#b0b0ff</color>
    +<style name="CustomTheme" parent="android:Theme.Light">
    +    <item name="android:windowBackground">@color/custom_theme_color</item>
    +    <item name="android:colorBackground">@color/custom_theme_color</item>
     </style>
     
    -

    Now use {@code CustomDialogTheme} instead of {@code Theme.Dialog} inside the Android +

    (Note that the color needs to supplied as a separate resource here because +the android:windowBackground attribute only supports a reference to +another resource; unlike android:colorBackground, it can not be given +a color literal.)

    + +

    Now use {@code CustomTheme} instead of {@code Theme.Light} inside the Android Manifest:

    -<activity android:theme="@style/CustomDialogTheme">
    +<activity android:theme="@style/CustomTheme">
     
    +

    Select a theme based on platform version

    + +

    Newer versions of Android have additional themes available to applications, +and you may want to use these while running on those platforms while still being +compatible with older versions. You can accomplish this through a custom theme +that uses resource selection to switch between different parent themes.

    + +

    For example, here is the declaration for a custom theme which is simply +the standard platforms default light theme. It would go in an XML file under +res/values (typically res/values/styles.xml): +

    +<style name="LightThemeSelector" parent="android:Theme.Light">
    +</style>
    +
    + +

    To have this theme use the newer "holo" theme when the application is running +on {@link android.os.Build.VERSION_CODES#HONEYCOMB}, you can place another +declaration for it in a file in res/values-11:

    +
    +<style name="LightThemeSelector" parent="android:Theme.Holo.Light">
    +</style>
    +
    + +

    Now use this theme like you would any other, and your application will +automatically switch to the holo theme if running on +{@link android.os.Build.VERSION_CODES#HONEYCOMB} or later.

    + +

    A list of the standard attributes that you can use in themes can be +found at {@link android.R.styleable#Theme R.styleable.Theme}.