我想在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