【发布时间】:2015-01-27 12:40:54
【问题描述】:
我正在尝试为我的 android 应用程序制作自定义主题。但问题是我无法更改操作栏主题。应用样式时,它给了我以下错误并关闭了应用程序:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
我不明白我做错了什么。这是我的代码:
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>
【问题讨论】:
-
您的 logcat 明确表示,如果您使用
appcompact -v7 library,则需要为您的应用使用Appcompact主题