Splash Screen Tutorial for Android
Fast forward to Android 12, which added the SplashScreen API. From Android 12 onward, all apps show a default splash screen, and developers can customize it according to their requirements.
build.gradle
implementation 'androidx.core:core-splashscreen:1.0.0-beta01'
styles.xml
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
<item name="windowSplashScreenBackground">@color/ic_launcher_background</item>
</style>
<style name="LegacySplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/legacy_splash_background</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
android:theme="@style/Theme.App.Starting"
Your file should look like this:
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LegacySplashActivity"
android:theme="@style/LegacySplashTheme"
android:exported="true">
<!--
launching Activity. Note: You will also need to comment out the equivalent intent-filter
block of the MainActivity above.
-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
MainActivity.kt
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
val splashScreen = installSplashScreen()
Your file should look like this:
override fun onCreate(savedInstanceState: Bundle?) {
// TODO: Install Splash Screen
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
startLoadingContent()