How to change the color of ActionBar in eclipse?

0

I'm studying how to change the color of my ActionBar , but I can not. I've tried everything but to no avail.

This is my MainActivity.java :

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

And my file style.xml :

<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- Este "colorPrimary" não funcionou -->
        <item name="colorPrimary">@color/material_blue_grey_900</item>
    </style>
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
</resources>
    
asked by anonymous 21.07.2015 / 02:36

1 answer

2

The traditional ActionBar evolves into the use of the Toolbar, which is much more flexible. I recommend that you use the principles of Material Design and make use of the Toolbar, so you can change your style of several ways, after all it is only a View.

<android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:id="@+id/toolbar_sort"
        android:title="Toolbar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:background="@color/theme_primary_dark" />

To set the Toolbar as an ActionBar

 setSupportActionBar(toolbar);

Do not forget to add in graddle dependencies

compile "com.android.support:appcompat-v7:22.2.1"

EDIT: In eclipse you can follow these steps to include libs

EDIT 2: I did not mention here, but you should change your Theme by removing ActionBar so that you can use the toolbar as ActionBar correctly.

<style name="Theme.MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
    <item name="colorPrimary">@color/theme_primary</item>
    <item name="colorPrimaryDark">@color/theme_primary_dark</item>
    <item name="colorAccent">@color/theme_accent</item>
</style>

<style name="MyActionBarStyle" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:background">@color/theme_primary_dark</item>
</style>
    
21.07.2015 / 14:22