简体   繁体   中英

Customize android action bar

I'm trying to create a new theme and customize the action bar:

<resources>

    <style name="Theme.Shappy.Red" parent="Theme.Sherlock.Light">
        <item name="android:actionBarStyle">@style/ActionBar.Shappy.Red</item>
        ...
        ... [some_other_customizations]
    </style>

    <!-- Action bar -->
    <style name="ActionBar.Shappy.Red" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">        
        <item name="android:background">#ffb70000</item>
        <item name="android:titleTextStyle">@style/ActionBar.Title.Shappy.Red</item>
    </style>

    <!-- Action bar text -->
    <style name="ActionBar.Title.Shappy.Red" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title">
            <item name="android:textColor">#ddffffff</item>
    </style>
</resources>

As you can see, I'm using Sherlock. This code works fine for API level 14, but it doesn't work for API level 10. I still see the Holo light like action bar. I think the code is correct because [some_other_customizations] are applied correctly. Do you have any suggestion? Thanks.

 <item name="android:actionBarStyle">@style/ActionBar.Shappy.Red</item>

and everything else with " android: " infront of it applies to the default actionbar. You have to put this in your styles as well:

<item name="actionBarStyle">@style/ActionBar.Shappy.Red</item>

This overrides the styles of the ABS. So your Styles should look like this in order to work in API Levels 13<:

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

<!-- Action bar -->
<style name="ActionBar.Shappy.Red" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="android:background">#ffb70000</item>
    <item name="background">#ffb70000</item>
    <item name="android:titleTextStyle">@style/ActionBar.Title.Shappy.Red</item>
    <item name="titleTextStyle">@style/ActionBar.Title.Shappy.Red</item>
</style>

<!-- Action bar text -->
<style name="ActionBar.Title.Shappy.Red" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title">
    <item name="android:textColor">#ddffffff</item>
    <item name="textColor">#ddffffff</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM