Splash Screen in Android

Aayush Puranik
2 min readJun 13, 2020

I have been working on a project and I need to implement a splash screen. Earlier I used to implement it by taking a splash activity and add a delay before navigating it to main activity. It was not a good solution and added artificial delay in loading a view for user and it was simply not worth.

I came across a cool solution and best part is it does not need to create a separate activity and we don’t need to add any delay for timers before user can see any data. The solution required creating a style for launcher theme and switching style to back to the style which is required.

Launcher Style
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@mipmap/ic_launcher</item>
</style>

a launcher style is created to act as a launcher screen

Base application theme
<style name="BasicAppStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="background">@android:color/holo_red_dark</item>
</style>

a basic app style is created to act as a style for our app, this theme will be visible to user

2 styles have been created in style.xml and implemented in following way.

Set app theme for application in AndroidManifest.xml file as LauncherStyle the theme which we have just created.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shoppinglistproject">

<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/LauncherStyle">
<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>

now we have taken care of splash screen, now we need to switch to base style and it will be set in main activity before setContentView method

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

--

--