0

I'm trying to make a custom theme for my android app. But the problem is that I can't change actionbar theme. When the style is applied, it gave me the following error and shutdown the app:

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

I can't understand what I'm doing wrong. Here's my code:

AndroidManifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AcelinkTheme">
        <activity
            android:name=".Dashboard"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light">
        <!-- Customize your theme here. -->
    </style>

</resources>

res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="AcelinkTheme"
        parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/AcelinkActionBar</item>
    </style>

    <!-- colors -->
    <color name="aceblue">#438eb9</color>

    <!-- ActionBar styles -->
    <style name="AcelinkActionBar"
        parent="android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/aceblue</item>
    </style>
</resources>
shadow
  • 21,823
  • 4
  • 63
  • 77
João Correia
  • 69
  • 1
  • 9
  • Your logcat clearly says that you need to use `Appcompact` theme for your app if you are using `appcompact -v7 library` – Piyush Jan 27 '15 at 12:49

2 Answers2

0

The exception is pretty clear : you need to use a theme that inherits from Theme.AppCompat, probably because you are using ActionBarActivity, which requires it as specified in the docs.

You can do this :

<style name="AcelinkTheme" parent="@android:style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/AcelinkActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="AcelinkActionBar" parent="@android:style/Widget.AppCompat.ActionBar">
    <item name="android:background">@color/aceblue</item>
</style>

For clarity, it is better to have colors defined in their own resource file IMHO.

2Dee
  • 8,609
  • 7
  • 42
  • 53
-1

According to this thread, you should change your parent to a Theme.AppCompat theme derivate:

<style name="AcelinkTheme"
    parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/AcelinkActionBar</item>
</style>

This link should also help you to customize your theme: Styling the Action Bar :)

Community
  • 1
  • 1
Sierra
  • 591
  • 9
  • 28