I want to implement Splash Screen using Jetpack Compose. In the old View system, we can just change the android:windowBackground via XML Theme.
How to do this in Compose?
I want to implement Splash Screen using Jetpack Compose. In the old View system, we can just change the android:windowBackground via XML Theme.
How to do this in Compose?
As I looked into the AndroidManifest.xml, I saw that the app is still using old themes.xml for its activities.
<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">
From here I just edit the theme to apply a windowBackground
<style name="Theme.AppName" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="android:windowBackground">@color/black</item>
</style>
I did not create a new style and just use the main style. It's enough to just apply a white Surface on the root composable to hide the splash background when the activity showed up.
The Window Background is something specific to Android itself, it tells the system what background this activity draws "At All times".
For example, an activity with no view at all can still have a background, as it is defined in its theme. This is actually used for stuff like Splash Screens, as they have no UI, just a background. Since the background of an activity takes no time to draw, while the UI can get delayed.
Compose is a UI framework, and any UI will only be drawn when it's ready, meaning it will only show when the activity is ready. So a splash screen is impossible in Compose. More like, it's unrelated.
If you just want to set a background to your entire UI, maybe put the entire UI in a Box with a background. Or set the background colour in the MaterialTheme. And if you're not using a theme, just make a common Composable that's just a Box