Customize android action bar

拜拜、爱过 提交于 2019-12-02 18:24:16

问题


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.


回答1:


 <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>



来源:https://stackoverflow.com/questions/13259055/customize-android-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!