0

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>
halfer
  • 19,824
  • 17
  • 99
  • 186
KillerByte
  • 35
  • 2
  • 7
  • 1
    Is there a particular reason you are using a `Holo` theme rather than `AppCompat`? – ianhanniballake Jan 03 '16 at 21:01
  • 1
    Both examples use `Theme.AppCompat` theme as base Theme. You are using old `Theme.Holo` in your code. – Sharjeel Jan 03 '16 at 21:02
  • There was no reason for me to use holo. I updated the code so that it uses the AppCompat as shown in the other answers, but I am still having the same problem. – KillerByte Jan 04 '16 at 00:08
  • 1
    Interesting thing... If I do this in my activity: `ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(android.R.color.white));` ...It works – KillerByte Jan 04 '16 at 00:30
  • That will work in single activity only, post your styles with AppCompat theme so we can grab the any possible error. – Harin Jan 04 '16 at 05:39
  • does it work for you. ? – Swaminathan V Jan 04 '16 at 14:20

2 Answers2

0

You have to sacrifice a slight blink showing the ActionBar style for few milliseconds when the app starts in case you want to use Java for styling any view because it sets up the layout according to layout definition on the style resources.

In case you want to hide from Java it will show a blink of actionbar at beginning.

So will be in other styling case.

So better you style it from style.xml but if the slight blink is ok go with Java.

halfer
  • 19,824
  • 17
  • 99
  • 186
erluxman
  • 18,155
  • 20
  • 92
  • 126
0

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.

KillerByte
  • 35
  • 2
  • 7
  • I should note that those items should be added in addition to the action bar styles that I was using earlier for backwards compatibility. – KillerByte Jan 05 '16 at 02:03