gpt4 book ai didi

android - ActionBarCompat : java. lang.IllegalStateException : You need to use a Theme. AppCompat

转载 作者:IT老高 更新时间:2023-10-28 13:04:18 28 4
gpt4 key购买 nike

我在 Android 2.3.5 上遇到 RuntimeException,但我使用 Theme.AppCompat (res/values/themes.xml)。这是电话:http://www.gsmarena.com/samsung_galaxy_y_s5360-4117.php

 <!-- res/values/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>

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

<style name="QueryActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@color/blueback</item>
<item name="android:background">@color/blueback</item>
<item name="backgroundSplit">@color/blueback</item>
<item name="android:backgroundSplit">@color/blueback</item>
</style>

</resources>

这是 values-v11 的文件。

 <!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="QueryTheme" parent="@android:style/Theme.Holo">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>

这是错误。

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txt2lrn.www/com.txt2lrn.www.LandingActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
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:102)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.txt2lrn.www.LandingActivity.onCreate(LandingActivity.java:95)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more

抱歉,我在 AndroidManifest.xml 中也定义了 android:theme="@style/Theme.Styled"。

最佳答案

如果您在 MainActivity 中扩展 ActionBarActivity,您还必须更改 values-v11 中的父主题。
所以 values-v11 中的 style.xml 将是 -

 <!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="QueryTheme" parent="@style/Theme.AppCompat">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>

编辑:我建议您停止使用 ActionBar 并开始使用 Android Design Support Library 中包含的 AppBar 布局。

关于android - ActionBarCompat : java. lang.IllegalStateException : You need to use a Theme. AppCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18063395/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com