Android Kotlin Splash screen.

Harshita Bambure
1 min readOct 6, 2021

--

A splash screen gives us a very cool launch when our application will start so let's start to implement a splash screen in our application

First of all, I added dependency in the build.Gradle(:app) file.

//splash screen
implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'

Then we need to add style to the themes.xml file.

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
// Set the splash screen background, animated icon, and animation duration.
<item name="windowSplashScreenBackground">@color/background_color</item>

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

// Set the theme of the Activity that directly follows your splash screen.
<item name="postSplashScreenTheme">@style/Theme.EcommerceApplication</item> # Required.
</style>

after that, we need to add a theme to the manifest file.

<application
android:theme="@style/Theme.App.Starting">
or<activity android:theme="@style/Theme.App.Starting">

Now we only need to add one line of code in our main activity before the set contains a view.

MainActivity.kt

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Handle the splash screen transition.
val splashScreen = installSplashScreen()

setContentView(R.layout.activity_main)


}
}

That's it. Happy Coding :)

--

--

Harshita Bambure
Harshita Bambure

Written by Harshita Bambure

Android Developer || WomenTech Global Ambassador at WomenTech Network. || Yoga Teacher || Member @WTM .

No responses yet