简体   繁体   中英

Change Color of Actionbar in Android

I am trying to change the background color of actionbar in my App but this is showing different on my app. Instead of coloring the actionbar the whole activity is color.

I am not sure why this is happening? I just want the main actionbar and settings actionbar colored.

Please check the screenshot.

Main Activity Map:

在此输入图像描述

Preference Settings:

在此输入图像描述

I also have transparent Actionbar with UP Navigation enabled for all my sub activities other than the main activity and preference settings activity.

I am not sure why it is showing like the above:

Here is style.xml (values-v14):

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:background">#FF5050</item>
</style>

<style name="dialogtheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"></style>

<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar.Transparent" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@android:color/transparent</item>
</style>

<!-- Activity Theme with transparent ActionBar -->
<style name="AppTheme.TransparentActionBar.Light" parent="@style/AppBaseTheme">
    <item name="android:actionBarStyle">@style/AppTheme.Light.ActionBar.Transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="android:icon">@android:color/transparent</item>
    <item name="android:actionBarTabTextStyle">@style/ActionBarTabTextStyle.Tabtheme</item>
    <item name="android:actionBarDivider">@drawable/verticallinefordivder</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.MapsLocation</item>
</style>

<style name="simpledialog" parent="android:Theme.Holo.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>

<style name="ActionBarTabTextStyle.Tabtheme" parent="@style/AppBaseTheme">
    <item name="android:textSize">18sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@android:color/black</item>
</style>

<style name="ActionBarTabStyle.MapsLocations" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator</item>
</style>

<style name="myPreferenceTheme" parent="@style/AppBaseTheme">
    <item name="android:textColor">@color/blue</item>
</style>

<style name="Widget.ActionButton" parent="@style/AppBaseTheme">
    <item name="android:background">?android:attr/actionBarItemBackground</item>
    <item name="android:paddingLeft">12dip</item>
    <item name="android:paddingRight">12dip</item>
    <item name="android:minWidth">56dip</item>
    <item name="android:minHeight">?android:attr/actionBarSize</item>
</style>

</resources>

A little change and you action bar will be red:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/AppTheme.Light.ActionBar</item>
</style>

<style name="dialogtheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"></style>

<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">#FF5050</item>

</style>

I have changed item in AppBaseTheme & AppTheme.Light.ActionBar . Now you are good to go. let me know if it works however working at my end :P

You can try set custom view in action bar.

actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(you_custom_layout);

I know this is not right answer to this question but if you want to edit your ActionBar, you can use this online Android Action Bar Style Generator .

At least you can create a style and check yours to find differences and learn how to edit your ActionBar.

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