java - 如何解决:IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代)
问题描述
我的应用程序无法在模拟器中运行。引用的错误是 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this Activity。
我已经阅读了许多类似的问题,包括: .IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
ActionBarCompat: java.lang.IllegalStateException: 你需要使用 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
主题根本不能用于应用程序主题。因此,请使用 anyTheme.AppCompat
作为应用程序的默认主题。为此,我可以举一个例子:
<style name = "AppBaseTheme" parent = "Theme.AppCompat">
或者
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
等等
希望它会起作用
推荐阅读
- c# - 将替代记录设置为真,如果它的偶数计数,否则离开最后一条记录
- php - 如何在 PHP 中拆分一些数字和数学运算符?
- python - 在python中的列表中查找连续的子序列
- bluetooth - 如何将浮点值从一个蓝牙模块发送到另一个(HC 05)
- yocto - 有没有办法为 Yocto 的 swupdate 层中的图像创建哈希(sha256)?
- python - 如何使用字符串定义函数名
- mysql - 制表符表不呈现某些列值。想知道为什么?
- python - eqNullSafe 函数在 spark 2.4.1 中引发错误
- python - ValueError:标签数=25 与样本数=56 不匹配
- git - GIT_SSH_COMMAND 环境变量作为 git 配置