'Android Changing Action Bar color

I want to change the Action Bar color, but I don't know how to do it. What should I add to change the style?

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

</style>

</resources>


Solution 1:[1]

This is all you need to change the color of the action bar:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#995544</item>
</style>

Solution 2:[2]

That code works for me and it also changes text color

<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="actionBarStyle">@style/AppTheme.ActionBar</item>
</style>

<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
    <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleText</item>
    <item name="titleTextStyle">@style/AppTheme.ActionBar.TitleText</item>
    <item name="background">@color/colorPrimary</item>
    <item name="android:height">150dp</item>
    <item name="height">60dp</item>
</style>

<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textSize">15dp</item>
    <item name="android:textColor">@color/colorAccent</item>
</style>

Solution 3:[3]

simple a single Line code

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.red)));

Solution 4:[4]

If your minSdk is 21 or higher, you can add the following:

<item name="colorPrimary">@color/yourColor</item>

If not then make the following changes:

  1. Your activity must extend AppCompatActivity

  2. Change your theme to @style/Theme.AppCompat.Light.NoActionBar

  3. Add this to the top of your activity xml file:

    <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

  4. Put this in your onCreate method after the super.onCreate call:

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);

  5. To change the color just replace ?attr/colorPrimary with @color/yourColor

Solution 5:[5]

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style

Here colorPrimary attribute helps you to change the color of action bar. For more details see this fig.

Solution 6:[6]

Please try the code below:

<style name="AppCompatTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:background">#ff540e9e</item>
    <item name="android:textColor">#ffffff</item>
</style>

Solution 7:[7]

At your theme.xml or/and theme.xml (dark), change the following android:statusBarColor which change the to status bar background color, toolbarNavigationButtonStyle change the back button color, actionBarStyle change the background and text color and displayOptions to show the text.

    <style name="Theme.Example" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <!-- Status bar color. -->
        <item name="android:statusBarColor">@color/backgroundDark</item>

        <!-- action bar color. -->
        <item name="toolbarNavigationButtonStyle">@style/Toolbar.Button.Navigation.Tinted</item>
        <item name="actionBarStyle">@style/Actionbar.dark</item>
        <item name="displayOptions">showHome|useLogo|showTitle</item>
    </style>

    <style name="Actionbar.dark" parent="Widget.AppCompat.Toolbar.Button.Navigation">
        <item name="background">@color/backgroundDark</item>
        <item name="titleTextStyle">@style/Actionbar.darktext</item>
        
    </style>

    <style name="Actionbar.darktext" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/white</item>
    </style>

    <style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
        <item name="tint">@color/white</item>
    </style>

enter image description here

Solution 8:[8]

You can customize the current theme for your app, in the res/values/styles.xml file try:

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
         // your custom styles added to theme        
     <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
 </style>


     //Cutomise your theme by specifying layout,color, font type etc:
 <style name="MyActionBarTheme" 
        parent="@android:style/Widget.AppCompat.Light.DarkActionBar">
     // sets the background color of the activity/app:  
     <item name="android:background">#33FF33</item>
 </style>

Then you will need to add your new custom theme name to your apps Manifest file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zoe stands with Ukraine
Solution 2 Josef K.
Solution 3 milan pithadia
Solution 4
Solution 5 Yaswanth Haridasu
Solution 6 Pang
Solution 7 Swee Kwang
Solution 8