-3

I've been trying to change the actionbar's color without any succes. I've been searching for a while now... I tried the solution of this post: How to change ActionBar color?

This is my styles.xml:

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#0091ea</item>
</style>
</resources>
Community
  • 1
  • 1
Beunzor
  • 83
  • 1
  • 11
  • [Ckeck my answer](http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us/27847656#27847656) – Apurva Mar 03 '15 at 18:56

4 Answers4

0

You can do it by this way

  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
        <item name="android:background">YOUR_COLOR_CODE</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">YOUR_COLOR_CODE</item>
    </style>

Obivously, you have to add this theme on your Activity in your AndroidManifest.

EDIT

Add those imports on your Activity

 import android.app.ActionBar;
 import android.graphics.drawable.ColorDrawable;

Just below on yout onCreate put this

ActionBar ab = getActionBar(); 
       ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#81a3d0"));     
       ab.setBackgroundDrawable(colorDrawable);

This works for me :

getActionBar().setBackgroundDrawable(new ColorDrawable(0xff1d97dd));

Let me know if it works :)

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
  • When I try the first way my app stops working after I launch it. I've tried the second way before I posted this topic, but somehow my actionbar does not change to the color I want – Beunzor Mar 03 '15 at 18:38
  • Did you add the theme on your Manifest? What is the error that are you facing with? – Skizo-ozᴉʞS ツ Mar 03 '15 at 18:39
  • Thanks It works! Although I don't think this is the proper way to change the color of the actionbar. But thanks for the help! – Beunzor Mar 03 '15 at 18:57
0

You can use the Android Asset Studio to create a custom ActionBar style, and therefore choose what color you want your AB to have.

You could also try the solution from this StackOverflow post How do I change the background color of the ActionBar of an ActionBarActivity using XML?

Quote:

Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:

<resources>
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">ANY_HEX_COLOR_CODE</item>
    </style>
</resources>

And, set "MyTheme" as theme for application / activity.

Community
  • 1
  • 1
freddiev4
  • 2,501
  • 2
  • 26
  • 46
0

To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. This property points to another style in which you can override the background property to specify a drawable resource for the action bar background.

When supporting Android 3.0 and higher only, you can define the action bar's background like this:

res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>
</resources>

Then apply your theme to your entire app or individual activities:

AndroidManifest.xml

<application android:theme="@style/CustomActionBarTheme" ... />

Source

Community
  • 1
  • 1
vdelricco
  • 749
  • 4
  • 15
0

You can set custom colors in your styles.xml.

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>

Then create a colors.xml file and set your colors there in hex format.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#F44336</color>
    <color name="primaryDark">#D32F2F</color>
    <color name="accent">#448AFF</color>
</resources>

Go here to learn more: https://developer.android.com/training/material/theme.html#ColorPalette