Changing ActionBar color in Style

0

I'm studying to develop Android applications, I'm making an App, but I can not change the color of my ActionBar. I'm developing for Android KitKat.

This is my style.xml

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

In my manifest is the theme 'AppTheme'.

What could be happening?

    
asked by anonymous 27.12.2014 / 21:16

2 answers

3

I was breaking my head, but it's settled. If you are using API 11 or higher, just add the OnCreate method in the .java file of your app's Main Activity (MainActivity.java, for example):

android.support.v7.app.ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#cor")));

Of course, remember to change the #cor to the hexadecimal code of the color you want.

If it does not work, try this variation:

ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#cor")));

In my case, only the first form worked. It is the easiest to change without having to move or create files in the values folder

    
24.06.2015 / 21:13
-2

If you are using AppCompat Material Design, you will define by the primary color:

<style name="AppTheme" parent="Theme.AppCompat.Light">
   <item name="colorPrimary">@color/material_blue_grey_900</item>
</style>

Otherwise (previous APIs), use in the parent attribute of your ActionBar the style coming from Widget, for example:

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    
28.12.2014 / 01:53