更改 Jetpack Compose 中的 android:windowBackground

Ris*_*rdi 5 android android-jetpack-compose

我想使用 Jetpack Compose 实现启动屏幕。android:windowBackground在旧的 View 系统中,我们只需通过 XML更改主题即可。

如何在 Compose 中执行此操作?

Ris*_*rdi 6

当我查看 时AndroidManifest.xml,我发现该应用程序仍在使用旧的themes.xml活动。

<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/Theme.AppName">
Run Code Online (Sandbox Code Playgroud)

从这里我只需编辑主题即可应用windowBackground

<style name="Theme.AppName" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="android:windowBackground">@color/black</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我没有创建新样式,只是使用主要样式。Surface当活动出现时,只需在根可组合项上应用白色即可隐藏飞溅背景。