Hello folks, in this tutorial, we will simply know the exact technique to create a launch screen or can say the splash-screen.
We have read my tutorial about the splash-screen and we’ve found the developers usually add a Runnable with a fixed time as a delay to solve it. That solution was not a good solution for us, because we don’t want to force our app users to wait when there is nothing to load actually. So Let us show you a genuine solution that shows the splash screen while the app is loading.
Implementation
Step 1: We have to design the splash screen layout as a drawable, we’ve used our splash screen logo as the fill bitmap,
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="translucent"> <item> <bitmap android:gravity="fill" android:src="@drawable/splash_screen" /> </item> </layer-list> |
Now, we need to define a theme with the windowBackground value as the previous drawable,
1 2 3 4 5 6 7 8 |
<style name="CustomSplashTheme" parent="AppTheme"> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> <!-- below one --> <item name="android:windowBackground">@drawable/splash_background</item> </style> |
Then, the theme must be assigned to the Splash Screen activity,
1 2 3 4 5 6 7 8 9 |
<activity android:name=".activity.SplashScreen" android:theme="@style/CustomSplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> |
Now we have achieved what we wanted to.
Conclusion
So we want to conclude that, With this technique, the splash screen is showed during the app initialization when it’s useful. And We can escape the splash activity that prevents delays associated with the activity creation. Keep the splash drawable as simple as possible, and you’ll like how fast it works.
Thanks for reading.
Stay Cool And Stay Updated!!!