You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tasks/actionbarsherlock/website/theming.html

38 lines
3.0 KiB
HTML

---
title: Theming
layout: default
---
<div class="row">
<div class="whole" id="theming">
<h1>Theming</h1>
<p>Theming of the action bar to work on all devices is a very straightforward and simple process. You should follow the existing theming recommendations for <a href="http://android-developers.blogspot.com/2011/04/customizing-action-bar.html">customizing the native action bar</a> with some minor tweaks.</p>
<p>An example of a customized action bar can be seen in the &ldquo;Styled&rdquo; example in the 'Demos' sample.</p>
<h3>Parent Themes</h3>
<p>In order for the custom action bar implementation to function your application must use <code>Theme.Sherlock</code>, <code>Theme.Sherlock.Light</code>, or <code>Theme.Sherlock.Light.DarkActionBar</code>, or your custom theme must use one of the aforementioned as its parent.</p>
<p>The themes should be defined in your manifest for the entire application or on a per-activity basis. You may also define the theme in the code of each activity <em>before</em> calling <code>super.onCreate(Bundle)</code>. This must be done for every activity on which you extend from one of the 'Sherlock' activity base classes and intend to use the action bar. More information on how to specify a theme can be found in the <a href="http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme">official Android documentation</a>.</p>
<h3>Mirrored Attributes</h3>
<p>Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal <code>android</code>-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation. Since both theming APIs are exactly the same you need only reference your customizations twice rather than having to implement them twice.</p>
<p>The easiest way to convey exactly what this entails is with an example. The following is the full theme from the &ldquo;Styled&rdquo; example mentioned above:</p>
<pre>&lt;style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
&lt;item name="actionBarStyle">@style/Widget.Styled.ActionBar&lt;/item>
&lt;item name="android:actionBarStyle">@style/Widget.Styled.ActionBar&lt;/item>
&lt;/style>
&lt;style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
&lt;item name="background">@drawable/bg_striped&lt;/item>
&lt;item name="android:background">@drawable/bg_striped&lt;/item>
&lt;item name="backgroundSplit">@drawable/bg_striped_split&lt;/item>
&lt;item name="android:backgroundSplit">@drawable/bg_striped_split&lt;/item>
&lt;/style></pre>
<h3>Dialog</h3>
<p>If you have a full activity that you wish to theme in the manner of a dialog there is also <code>Theme.Sherlock.Dialog</code> and <code>Theme.Sherlock.Light.Dialog</code> themes which will provide a consistent Ice Cream Sandwich look.</p>
<p>No additional dialog themes will be included. If you require some of the more advanced features of dialogs they must be implemented yourself.</p>
</div>
</div>