android - 更新到最新版本后,您需要在此活动中使用 Theme.AppCompat 主题(或后代)
问题描述
我有一个几个月前可以工作的应用程序,我在用最新版本更新了各种实现文件后才编译它。现在,当我尝试运行它时,我得到“您需要在此活动中使用 Theme.AppCompat 主题(或后代)”。好吧,我知道这意味着什么,但在这种情况下,这正是我正在做的事情。显然,其中一个实现文件(我猜是androidX)发生了一些变化,并且它看到的东西与以前不同。
无论如何,这是相关的信息。有人看到我需要改变什么吗?
<application
android:name=".MyApplication"
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/Theme.AppCompat"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".ui.StartScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_start_screen"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.android.myapp.ui.StartScreenActivity.onCreate(StartScreenActivity.kt:32)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()
setContentView(com.android.myapp.R.layout.activity_start_screen)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"
tools:context=".ui.StartScreenActivity">
</FrameLayout>
如您所见,我已经将 Theme.AppCompat 用于应用程序和 Activity。不知道我还能做什么。我尝试重新启动 Android Studio 和其他各种方法无济于事。
有什么想法吗?
解决方案
我遇到了同样的问题,似乎是 MaterialComponents 1.1.0 版本的错误。我更新com.google.android.material:material:1.2.0-alpha06
并解决了问题
推荐阅读
- javascript - 多图选择禁用低位时调整序号
- vue.js - Webix 作为 Vue 调用方法
- amazon-web-services - 在命令行上创建秘密值时出现问题
- php - PhpStorm 语法高亮在其中不起作用标签
- excel - 如果单元格包含这个或那个粘贴到另一张纸上
- java - 在 Java 中获取 CET 冬季时间
- angular - NATIVESCRIPT 错误 ReferenceError:找不到变量:IDBIndex
- git - Git 没有提示我输入密码
- zend-framework2 - 如何使用 PHPUnit 版本 8.5.1 配置 Zend 框架 2.4 的代码覆盖率?
- ioc-container - 如何检查接口是否已在 StructureMap 中注册?