Android: Splash Screen with Kotlin
Roberto Orozco Aug 3
There are different opinions on whether having a splash screen on your Android application or not.
Personally, I think splash screens are a good place where you can showcase your app's nice design and give your users a good first impression.
So, this is how I've been implementing splash screens on my recent Android apps with Kotlin.
Static vs Animated
I've used both static and animated splash screens and here are some thoughts.
- Showed only in the launching of your app before onCreate() is called.
- You're not wasting your users time.
- Not intended to run operations while the splash screen is shown.
- You can show a cool animation and custom design.
- Flexibility to perform some operations while the animation finishes.
- Users can get bored if the animation is useless or if it takes too long.
Static Android Splash Screen
Create the drawable file that we will use as background in the entry activity, by using a background, the app will show it without having to inflate a layout file.
Create a theme in the styles file with no action bar that uses the splash drawable as the background to set it in the entry activity.
Set the new style as a theme for the splash activity in your app manifest.
Add the code to navigate to the next activity as soon as the app has finished loading.
Animated Android Splash Screen
When I use animated splash screens I like to keep showing the static part of the splash screen on the initialization so I repeat steps 1, 2 and 3 from above and just add the animation functionality.
For the animated splash screen, we will inflate a layout with the element or elements we want to animate. In this case, I'm just animating a textview.
Now we need to modify the splash activity to enable the animation and perform some loading operations in the meantime. Here's how my splash activity looks like.
That's it, please share your thoughts on Android splash screens and your comments on how to improve this implementation.