我想在android应用程序中自定义一个操作栏。Android Customized Actionbar
但没有奏效。
这是我的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<color name="custom_white_color">#ffffff</color>
<color name="custom_blue_color">#2E4372</color>
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/custom_white_color</item>
</style>
的代码在 “AndroidManifest” 我打电话是这个主题的应用程序
android:theme="@style/CustomActionBarTheme" >
但是当我执行此代码发生以下错误
03-03 00:44:43.456 2467-2467/br.com.lzl.colorlist E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: br.com.lzl.colorlist, PID: 2467
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.lzl.colorlist/br.com.lzl.colorlist.HomeActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at br.com.lzl.colorlist.HomeActivity.onCreate(HomeActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
如果我尝试使用Theme.Appcompat自定义不起作用。
有没有人有线索来解决这个问题?
谢谢你!
您是否导入了appcompat库? – 2015-03-03 01:11:15
我想我应该试试看看你是否想要做材质,全息或其他主题? – tachyonflux 2015-03-03 01:39:12
是的,我正在使用Android Studio,它已经将AppCompat添加到库中。 – 2015-03-03 12:07:02