How to Add a splash Screen with Android 12 Api

 Step 1 :- Add this dependency  and Sync 

core-splashscreen ={ group = "androidx.core" , name="core-splashscreen" , version="1.0.1"}


implementation(libs.core.splashscreen)

Step 2 :- create a new theme file (here named "app_splash.xml")

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppSplashTheme" parent="Theme.SplashScreen.IconBackground">
<item name="android:windowNoTitle">true</item>

<!-- Set the splash screen background, animated icon, and animation
duration. -->
<item name="windowSplashScreenBackground">@color/black</item>

<!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
drawable. One of these is required. -->
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<!-- Required for animated icons. -->
<item name="windowSplashScreenAnimationDuration">200</item>

<!-- Set the theme of the Activity that directly follows your splash
screen. This is required. -->
<item name="postSplashScreenTheme">@style/Theme.AIDoctor</item>


</style>
</resources>


Step 3 :- Edit your App Manifest and add this theme to your activity by defult 

<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.AppSplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


Step 4: All done add this line in your MainActivity.kt 

installSplashScreen()


Post a Comment

0 Comments