Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change android:windowBackground in Jetpack 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?

like image 516
Risal Fajar Amiyardi Avatar asked Jul 25 '26 03:07

Risal Fajar Amiyardi


1 Answers

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.

like image 83
Risal Fajar Amiyardi Avatar answered Jul 26 '26 17:07

Risal Fajar Amiyardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!