Styling Sherlock actionbar – Change actionbar color

Just few step to change the style of Sherlock actionbar. Here it goes like this

1)make your application theme something like shown below

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyCustomTheme" parent="Theme.Sherlock">
     <-- This one is for below android 3.x device-->
     <item name="actionBarStyle">@style/ActionBar</item>
     <-- This one is for android 3.x or greater device-->
     <item name="android:actionBarStyle">@style/ActionBar</item>
     <style>

</resources>

2) Define style for action bar

 <!-- style for actionbar(Equivalent to titlebar) -->
    <style name="ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="background">@drawable/actionbar_bg_top</item> -----------(1)
        <item name="android:background">@drawable/actionbar_bg_top</item>
       
        <item name="android:titleTextStyle">@style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item> ----(2)
        <item name="titleTextStyle">@style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
    </style>
<!-- define text style of Action bar Title -->
 <style name="customTextAppearance.Sherlock.Widget.ActionBar.Title" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textSize">14dp</item>
        <item name="android:textColor">#083647</item>
        <item name="android:shadowColor">#4ccfff</item>
        <item name="android:shadowDy">3</item>
    </style>

equation 1–> define the background color of action bar. @drawable/actionbar_bg_top may be in the form of nine patch image or color
equation 2 –>define the style of Text that appear as title in Sherlock actionbar

3)Use the theme on application in android manifest file


<application
       
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MyCustomTheme" >
        <activity
            android:name=".YourMainActivtiy"
           
            android:configChanges="orientation"
            android:label="app" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application

That’s all for changing color of actionbar in Sherlock action bar
here is the affect
device-2013-02-15-143813

Enjoy android styling 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s