如何在 Android 12 的 SplashScreen api 中使用动态颜色?

Rar*_*res 5 android android-12 android-api-31 android-splashscreen

我试图使 android 12 启动屏幕的背景使用 @android:color/system_neutral1_900 作为背景,但正如我所看到的,颜色仅在启动屏幕之后加载。有什么办法可以在启动屏幕上使用它吗?

<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
    <!-- Set the splash screen background, animated icon, and animation duration. -->
    <item name="windowSplashScreenBackground">@android:color/system_neutral1_900</item>
</style>
Run Code Online (Sandbox Code Playgroud)

颜色不会出现,它使用默认的灰色。我还尝试了其他 system_ 颜色,出现了相同的结果。使用 @android:color/black 或十六进制颜色可以。

小智 0

根据此链接尝试使用此项目作为主应用程序主题的一部分

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowSplashScreenBackground">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)