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 customizing the native action bar with some minor tweaks.
An example of a customized action bar can be seen in the “Styled” example in the 'Demos' sample.
In order for the custom action bar implementation to function your application must use Theme.Sherlock
, Theme.Sherlock.Light
, or Theme.Sherlock.Light.DarkActionBar
, or your custom theme must use one of the aforementioned as its parent.
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 before calling super.onCreate(Bundle)
. 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 official Android documentation.
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android
-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.
The easiest way to convey exactly what this entails is with an example. The following is the full theme from the “Styled” example mentioned above:
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar"> <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item> <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item> </style> <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <item name="background">@drawable/bg_striped</item> <item name="android:background">@drawable/bg_striped</item> <item name="backgroundSplit">@drawable/bg_striped_split</item> <item name="android:backgroundSplit">@drawable/bg_striped_split</item> </style>