How to Make a Splash Screen right way in Android

Ashish Patel
3 min readOct 31, 2020

This tutorial shows you how to implement a splash screen from scratch in Android studio using Kotlin.

Here you will learn how to make a splash screen without creating another activity, By doing this every time your users have to wait for some second and it’s making a bad impression no user experience. follow this article to learn how to do it.

1. Start a new project on android studio. 💻

If you don’t know how to do so. Just go to Files →New →New Project. And then choose an Empty Project and fill in the below details of your choice or follow mine for consistency.

Create an Empty Activity with the above details
Create an Empty Activity with the above details

2. Import app logo 😃

For splash screen or any drawable resource try to use SVG image because it has a high resolution on any device and it’s best practice to use vector assets as an image resource.

Follow these step to import your local SVG files in android studio. Right-click on drawable directory →New →Vector Assets and select your logo from your device.

Import a Logo with the above details

3. Create a drawable file 🟩

This drawable will display as our splash screen. We use a logo which we have already and give it to the background color.

For creating a drawable file. Right-click on drawable directory →New →Vector Assets and select your logo from your device.

Create a Drawable file with the above details

After creating a drawable file we will give a background color to it and give a gravity center so logo stays in the center of the screen.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/splash_screen_bg" />
<item
android:drawable="@drawable/ic_madhyam"
android:gravity="center" />
</layer-list>

4. Create a style for splash screen 🎇

Here I am using android studio 4.1 So theme.xml contains my app style you can find your theme.xml on following path Res→Values →Themes→Theme.xml.

Give a name to your style here my style name is SplashScreenTheme. Parent style should not have action bar so use NoActionBar.So here we used our earlier rmade drawable file and don’t forget to set status bar color as your splash screen background color.

<style name="SplashScreenTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowBackground">@drawable/ic_splash_screen_image</item>
<item name="android:statusBarColor">@color/splash_screen_bg</item>
</style>

5. Set SplashScreen style in AndroidMenifest file ⚒

Here we set android: theme as our custom theme which we made for splash screen

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ashishxcode.splashscreen">
<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/SplashScreenTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

6. Set Default Theme 📱

Why we have to set to default theme because we set android:theme as a custom splash screen theme, So after completing splash screen our app has to use default theme otherwise we will get tons for error.

apply setTheme() method before setContentView because you know that setContentView link our app layout with our kotlin file.

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.Theme_SplashScreen)
setContentView(R.layout.activity_main)
}
}

Source Code

https://github.com/ashishxcode/SplashScreen 🐱‍💻

Happy Coding 👨🏻‍💻

Congratulations you have successfully completed the tutorial of implementing “How to Make a Splash Screen right way in Android”. I hope you enjoyed it and learned something new today. Tell your friends that don’t make another activity for the splash screen and delay it for some seconds it’s making a bad impact on your app UX. Thank you guys for spending your time reading my tutorial. Stay tuned for more updates. Until then goodbye. Have a nice day.

--

--

Ashish Patel

Technologist 👩🏻‍💻 | Foodie 🥗 | Nethead 💻