Creating Splash Screen on Android: A HelloWorld Project!
Android Splash Screen is the first screen visible to the user when the application’s launched. Splash screen is one of the most vital screens in the application since it’s the user’s first experience with the application.
Usually developers use splash screen to display the app’s logo along with some cool animations and effects to make the app feel more proffessional and complete. With minimal coding efforts and time, splash screens are great way of making your app more better.
There are two most common approaches for implementing a Splash Scree :
- Using Launcher Theme
- The classical way (Dedicated Activity)
Using Launcher Theme
This should be your ideal choice for implementing splash screen, in this method we display the splash screen during the cold start of our app, i.e. when our app is loading it’s data, this way we could avoid delaying the user but since we are making just an HelloWorld app with just one activity, our app would load almost instantly, skipping directly to the MainActivity, so we’ll be implementing splash screen using the second method.
The Classical Way
In this method, we use a dedicated activity for displaying splash screen, this way we have more control over our splash screen and we can implement some really good things like animations and other fancy stuff but it is not recommended to intentionally delay our user however in some situations a dedicated splash screen (like in Gaming Applications) maybe more useful.
So, let’s jump into our HelloWorld App!
Implementation
Create your android project as you would normally do with an empty MainActivity
First let’s start by creating Theme for our splash screen. Inside your styles.xml
file add following code
We use the dot notation to inherit all the properties of AppTheme
and override some properties in our new AppTheme.NoActionBar
to tune our splash screen.
Now create a new layout for our splash activity, right click on your app module -> new -> Activity -> Empty Activity
and name your activity as SplashActivity
(or whatever you like)
Now let’s code our SplashActivity
Here you can change the valueSPLASH_TIMEOUT
to match your needs or even direct user to some other activity using intents.
Now that we have our driver code ready, let’s design our actual splash screen
You can configure your activity_splash
as per your needs, I am just putting my app logo at the center and it’s name at the bottom.
I have kept my MainActivity
empty and my activity_main
layout just shows HelloWorld so nothing fancy there. Now let’s jump into one of the most important part of out app, the AndroidManifest
file
Change your SplashActivity
to launcher activity and MainActivity
to other activity and also change the theme of your launching activity to AppTheme.NoActionBar
Now our app would first load the SplashActivity
with AppTheme.NoActionBar
theme which forms our splash screen and then jump to ourMainActivity
Now you are ready to create some cool splash screens for your android apps!
Happy Coding! 🎉