Splash API throws 您需要使用 Theme.AppCompat 主题(或后代)与此 activity

Splash API throws You need to use a Theme.AppCompat theme (or descendant) with this activity

我正在尝试按照 this android 文档使用他们的 Splash API 以便我的启动画面可以在我支持的任何版本 android 上运行并且我撞墙了我完全遵循了它,并且在调试我的应用程序时不断得到这个:

You need to use a Theme.AppCompat theme (or descendant) with this activity.

// AndroidX Components
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.browser:browser:1.4.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.constraintlayout:constraintlayout-solver:2.0.4'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-splashscreen:1.0.0-beta02'
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.4.1"
implementation "androidx.navigation:navigation-dynamic-features-fragment:2.4.2"
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation "androidx.navigation:navigation-runtime-ktx:2.4.2"
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.paging:paging-runtime-ktx:3.1.1'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation "androidx.security:security-crypto:1.1.0-alpha03"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.webkit:webkit:1.4.0'
implementation "androidx.work:work-runtime-ktx:2.7.1"

// Firebase & Google Play Services
implementation 'com.google.android.gms:play-services-base:18.0.1'
implementation 'com.google.android.play:core:1.10.3'
implementation 'com.google.android.play:core-ktx:1.8.1'
implementation platform('com.google.firebase:firebase-bom:29.0.4')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.google.gms:google-services:4.3.10'

// Glide
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation 'com.github.bumptech.glide:recyclerview-integration:4.13.1'
kapt 'com.github.bumptech.glide:compiler:4.13.1'

// Hilt
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
implementation 'androidx.hilt:hilt-work:1.0.0'
implementation 'com.google.dagger:hilt-android:2.41'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
kapt 'com.google.dagger:hilt-android-compiler:2.41'

// Ktor
implementation 'io.ktor:ktor-client-android:2.0.0'
implementation 'io.ktor:ktor-client-auth:2.0.0'
implementation 'io.ktor:ktor-client-content-negotiation:2.0.0'
implementation 'io.ktor:ktor-serialization-kotlinx-json:2.0.0'

// Kotlin & Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1-native-mt'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1-native-mt'
implementation 'org.jetbrains.kotlinx:kotlinx-datetime:0.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2'

// Misc
implementation 'com.auth0.android:jwtdecode:2.0.1'
implementation "com.github.skydoves:androidveil:1.1.2"
implementation 'com.github.yalantis:ucrop:2.2.8'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.jakewharton.timber:timber:5.0.1'

// Unit Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
<style name="App.Material" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:navigationBarColor">@color/primary</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textColorPrimary">@color/textColor</item>
    <item name="android:textColorSecondary">@color/mutedTextColor</item>
    <item name="actionModeCloseDrawable">@drawable/close</item>
    <item name="actionModeStyle">@style/ActionModeStyle</item>
    <item name="actionMenuTextColor">#ffffff</item>
    <item name="colorAccent">@color/primary</item>
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary</item>
    <item name="colorError">@color/error</item>
    <item name="colorPrimaryVariant">@color/primary</item>
    <item name="colorSecondaryVariant">@color/primary</item>
    <item name="colorOnPrimary">#ffffff</item>
    <item name="colorOnSecondary">#ffffff</item>
    <item name="colorOnBackground">@color/textColor</item>
    <item name="colorOnError">#ffffff</item>
    <item name="shapeAppearanceLargeComponent">@style/ShapeAppearance.LargeComponent</item>
    <item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.MediumComponent</item>
    <item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.SmallComponent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="App.Material.Splash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/primaryColor</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash_logo</item>
    <item name="postSplashScreenTheme">@style/App.Material</item>

    <!-- Status bar and Nav bar configs -->
    <item name="android:statusBarColor" tools:targetApi="l">@color/primaryColor</item>
    <item name="android:navigationBarColor">@color/primaryColor</item>
</style>
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?)
{
    val splashScreen = installSplashScreen()

    super.onCreate(savedInstanceState, persistentState)

    // Keep the splash screen visible for this Activity
    splashScreen.setKeepOnScreenCondition { true }

    // ... rest of my app's code
}

我相信我遵循了它的设置方式,所以此时我只是迷失了为什么它根本不工作并且不适应。

经过大量试验,我发现了我的问题,并且我已经 reported 他们的错误跟踪器上的问题。显然,如果您在 onCreate() 上设置了 persistentState,它会触发此错误,但删除它后,应用程序将不会崩溃。

如果有人遇到这个问题,希望这对您有所帮助,希望 Google 的好人会解决这个问题,或者记下您不能将那个参数与启动 API 一起使用。