我的应用程序无法在模拟器中运行。引用的错误是 java.lang.IllegalStateException:您需要在此 Activity 中使用 Theme.AppCompat 主题(或后代)。
我读过许多类似的问题,包括: .IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat
但这些都不起作用。
res>values>styles.xml 文件中的代码是:
<resources>
<style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
<item name = "android:colorPrimary">@android:color/holo_blue_bright</item>
<item name = "android:colorPrimaryDark">@android:color/holo_blue_dark</item>
<item name = "android:colorAccent">@android:color/holo_red_dark</item>
</style>
</resources>
src>main>AndroidManifest.xml 文件中的代码为:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.hbpm1">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppBaseTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
如果有人能提供帮助,我将非常感激:)
最佳答案
应用程序主题不能是<style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
,因为TextAppearance
theme 根本不能用于应用程序主题。因此,使用任何 Theme.AppCompat
作为您的应用程序的默认主题。
为此,我可以举一个例子:
<style name = "AppBaseTheme" parent = "Theme.AppCompat">
或
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
等等
希望能成功
关于java - 如何通过此 Activity 解决 : IllegalStateException: You need to use a Theme. AppCompat 主题(或后代),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58327927/