Android color change action bar

I want to change the color of the action bar, 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>
+4
source share
5 answers

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

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

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

If not, make the following changes:

  • Your activity should expand AppCompatActivity

  • Change the theme to @style/Theme.AppCompat.Light.NoActionBar

  • Add this to the top of your xml activity 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"/>

  • Put this in your method onCreateafter the call super.onCreate:

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

  • To change color, simply replace ?attr/colorPrimarywith@color/yourColor

0
source

, :

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

,

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

0

, / :

//First you need to declare the custom theme in your styles file    
</style>

   <style name="MyCustomTheme" parent="@android:style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBarTheme</item>

  </style>
//Then you provide details on it layout/color etc
  <style name="MyActionBarTheme" parent="@android:style/Widget.AppCompat.Light.DarkActionBar">
       <item name="android:background">#33FF33</item>
      </style>

don't forget to add a new name for your personalized theme to your application manifest file

-1
source

All Articles