KillerByte KillerByte - 3 years ago 183
Android Question

Cannot Change Background Color For Action Bar

I have already tried looking at the following threads to find the answer to my question:

Android unable to change background color of ActionBar

Change Background color of the action bar using AppCompat

...but none of those solutions have helped me fix the problem.

I am attempting to change the background color (among other things) of the actionbar. So far I have been able to change the styles for everything else. Here is my styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
<item name="actionBarStyle">@style/AppTheme.ActionBar</item>
<item name="android:windowBackground">@color/dark_green</item>
<item name="android:buttonStyle">@style/AppTheme.Button</item>
<item name="android:editTextStyle">@style/AppTheme.EditText</item>
<item name="android:listViewStyle">@style/AppTheme.ListView</item>
<item name="android:windowActionBar">true</item>
<!--<item name="android:colorBackground">@color/dark_green</item>-->
</style>

<style name="AppTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/dark_green</item>
<item name="background">@color/dark_green</item>
<item name="android:colorPrimary">@color/dark_green</item>
<item name="android:colorPrimaryDark">@color/dark_green</item>
</style>

<!-- Button theme -->
<style name="AppTheme.Button">
<item name="android:background">@drawable/background_button</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:padding">20dp</item>
</style>

<!-- Edit Text Theme -->
<style name="AppTheme.EditText">
<item name="android:background">@drawable/background_edittext</item>
<item name="android:padding">14dp</item>
<item name="android:layout_marginBottom">16dp</item>
<item name="android:textColorHint">@color/light_gray</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:textSize">20dp</item>
</style>

<style name="AppTheme.ListView">
<item name="android:textColor">@color/text_color</item>
<item name="android:divider">@android:color/transparent</item>
</style>

<declare-styleable name="FixedAspectRatioFrameLayout">
<attr name="aspectRatioWidth" format="dimension" />
<attr name="aspectRatioHeight" format="dimension" />
</declare-styleable>
</resources>


Here is my Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.myapp.app">

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/myapp_button"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login" />
<activity
android:name=".HomeActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ListOffersActivity"
android:parentActivityName=".HomeActivity"
android:launchMode="singleTop"/>
<activity
android:name=".ViewOfferActivity"
android:label="@string/title_activity_view_offer"
android:parentActivityName=".ListOffersActivity">
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".HomeActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="io.myapp.app.HomeActivity" />
</activity>
<activity android:name=".ListSavedOffersActivity"
android:label="Saved Offers"
android:parentActivityName=".HomeActivity"
android:launchMode="singleTop"></activity>
</application>

</manifest>

Answer Source

Well, after a couple days of fiddling with it, I found out that the problem was mainly due to the fact that android (with its new material theme and all...) changes the color in the actionbar when you change the following properties:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:colorPrimary">@color/dark_green</item>
        <item name="android:colorPrimaryDark">@color/darker_green</item>
</style>

This properly set the color of the actionbar to @color/dark_green.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download