dimanche 3 mai 2015

Android: How to change my action bar background color

I used Android Studio to create a project with activity that uses ListView and a navigation drawer template, I'm targeting API 14+ and I'm testing on Galaxy Note 3 Kitkat - the result of the code below is "Nothing" the action bar color is black (very dark grey) not blue as I intend.

in build.gradle file

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'}

in AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

in Styles.xml (where I have AppTheme)

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
    <item name="android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item>
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

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

in blue_action_bar_color.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://ift.tt/nIICcg">
    <solid android:color="@color/action_bar"/>
</shape>

in colors.xml

<color name="action_bar">#3b5b98</color>

So what am I missing here?

EDIT1:

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

EDIT2:

I can't use

<style name="AppTheme" parent="android:Theme.Holo.Light">

as my application crash with error message:

 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

Aucun commentaire:

Enregistrer un commentaire