Implement a proper launch screen (splash screen) in a modern Android app built with Jetpack Compose and Material 3, following Googleโs official recommendations.
1. Add the SplashScreen dependency
In your build.gradle
(module):
implementation("androidx.core:core-splashscreen:1.0.0")
2. Define the XML theme for splash and post-splash
In res/values/themes.xml
:
<resources>
<!-- Base theme used after the splash -->
<style name="Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar" />
<!-- Splash theme showing the icon and background -->
<style name="Theme.MyApp.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo</item>
<!-- For branding images
<item name="android:windowSplashScreenBrandingImage">@drawable/ic_branding_logo</item> -->
<item name="windowSplashScreenBackground">@color/white</item>
<item name="windowSplashScreenAnimationDuration">500</item>
<item name="postSplashScreenTheme">@style/Theme.MyApp</item>
</style>
</resources>
3. Apply the splash theme in the AndroidManifest
<application
android:theme="@style/Theme.MyApp.Splash"
... >
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.MyApp.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
4. Install the SplashScreen in your MainActivity
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Enable the SplashScreen API
val splash = installSplashScreen()
// Only if you need to wait for initial data:
splash.setKeepOnScreenCondition { !uiState.isReady }
super.onCreate(savedInstanceState)
setContent {
AppTheme {
AppNavHost()
}
}
}
}