Holdfast33
Holdfast33

Reputation: 132

How can I change the color of the Android Action Bar?

I am trying to change the color of my Android ActionBar, but my app is closing with an error each time. I have tried all other suggestions and fixes in other posts, but they dont seem to work for me. Also - minSdkVersion 19

Error:

03-17 11:25:56.884  11999-11999/ca.holdfastonline.menu_test_02 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: ca.holdfastonline.menu_test_02, PID: 11999
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.holdfastonline.menu_test_02/ca.holdfastonline.menu_test_02.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)

My Styles.xml

<resources>
    <style name="QueryTheme" parent="@style/Theme.AppCompat">
        <!-- Any customizations for your app running on devices with Theme.Holo here -->
    </style>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
        parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#2980b9</item>
    </style>
</resources>

My AndroidManifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/QueryTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/CustomActionBarTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Thank you.

Upvotes: 0

Views: 124

Answers (2)

Tristan
Tristan

Reputation: 3578

This is probably because in your Java file you are using ActionBarActivity and you should be using Activity.

More Info Basically you are using ActionBarActivity, this activity requires a Theme.AppCompact which is where your error is coming from. To fix this you would need to change to use the regular Activity or just use Theme.AppCompact

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006539

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

You have only one activity. It is using @style/CustomActionBarTheme. Your definition of CustomActionBarTheme has it inheriting from Theme.Holo.Light.DarkActionBar. That is not an AppCompat theme. Change Theme.Holo.Light.DarkActionBar to Theme.AppCompat.Light.DarkActionBar.

Upvotes: 1

Related Questions