Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling ActionBar Sherlock

I'm trying to customize my sherlock action bar, but nothing that I code in my style.xml is recognized.

In my manifest file:

 android:theme="@style/Theme.Sherlock"

My style.xml:

<resources>
<style name="Theme.MyAppTheme" parent="Theme.Sherlock">
    <item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
</style>

<style name="Theme.MyAppTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">#222222</item>
    <item name="android:height">64dip</item>
    <item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
    <item name="android:textColor">#fff</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">32sp</item>
</style>

I'm calling my actionbar this way:

public class MainActivity extends SherlockActivity {

 com.actionbarsherlock.app.ActionBar actionbar;

 ...

 actionbar = getSupportActionBar();

 ... }

There is no problem in showing the actionbar, but the same does not show any customization coded in style.xml, can someone help me? Thankful.

like image 771
Artur Couto Avatar asked Jan 02 '13 01:01

Artur Couto


2 Answers

It's because you are applying the same original style in the manifest file android:theme="@style/Theme.Sherlock" which doesn't make any difference. You have prepared the custom style with name Theme.MyAppTheme, having parent as Theme.Sherlock. So, you need to declare your customized style(Theme.MyAppTheme) in your manifest file like android:theme="@style/Theme.MyAppTheme". Even you have to include without android prefix attributes too like below as the other answerer also said. Hope this helps. Even you can refer this too.

 <style name="Theme.MyAppTheme" parent="Theme.Sherlock.Light">
            <item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
        <item name="actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>        
    </style>

    <style name="Theme.MyAppTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">#222222</item>
    <item name = "background">#222222</item> 
    <item name="android:height">64dip</item>
     <item name="height">64dip</item>

    <item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textColor">#fff</item>
        <item name="textColor">#fff</item>
        <item name="android:textStyle">bold</item>
        <item name="textStyle">bold</item>
        <item name="android:textSize">32sp</item>
        <item name="textSize">32sp</item>
 </style>
like image 84
Kanth Avatar answered Sep 22 '22 20:09

Kanth


Use this and you don't need to create your own style

Action Bar Style Generator

like image 34
Zyoo Avatar answered Sep 23 '22 20:09

Zyoo