在更新到最新版本后,您需要在此活动中使用Theme.AppCompat主题(或后代)

问题描述 投票:0回答:1

我有一个可以在几个月前正常工作的应用程序,我是在使用最新版本更新各种实现文件后才进行编译的。现在,当我尝试运行它时,我得到“您需要在此活动中使用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。不知道我还能做什么。我尝试重新启动Android Studio和其他各种方法都无济于事。

有什么想法吗?

android android-theme
1个回答
0
投票

尝试从您的代码中删除actionBar?.hide()并使用:

Theme.AppCompat.Light.NoActionBar代替Theme.AppCompat作为您的活动样式

© www.soinside.com 2019 - 2024. All rights reserved.