Artur Couto
Artur Couto

Reputation: 498

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.

Upvotes: 5

Views: 8918

Answers (3)

Zyoo
Zyoo

Reputation: 773

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

Action Bar Style Generator

Upvotes: 3

Kanth
Kanth

Reputation: 6751

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>

Upvotes: 8

Ahmad
Ahmad

Reputation: 72553

This:

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

is for the default ActionBar, notice the 'android:'. You have to style it like this:

     <resources>
    <style name="Theme.MyAppTheme" parent="Theme.Sherlock">
        <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="android:height">64dip</item>
        <item name="background">#222222</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="android:textStyle">bold</item>
        <item name="android:textSize">32sp</item>
        <item name="textColor">#fff</item>
        <item name="textStyle">bold</item>
        <item name="textSize">32sp</item>
    </style>

Upvotes: 0

Related Questions