The way Google does
The right way
What is a splash screen?
Splash screen is the screen containing a logo or a background of the app that is to be displayed when we open the app. Splash screen is displayed during the loading of our main app activity in background.
Why adding splash screen is a good practice?
When an app is loaded, a blank white/black is displayed for few seconds while the app’s main activity loads. To show user something during that time, related to your app, can be a logo, some kind of animation or any other background effect. Splash screen also creates an initial impression to the user about your app.
How to create splash screen for your app? The best way to do so?
The right, easiest and best way to do so.
- In your existing project/ new project, right click on the java directory and create new java class named “SplashScreen” or whatever you like.
- In “SplashScreen” class, extend the class to AppCompatActivity and Override onCreate method .
- Now, right click the drawable directory and create new Layout resource file(xml file) named “background_splashscreen”.
- Add the logo/image you wish to add in the splash screen named “logo”.
- Change the selector(or any other) to layer-list.
- Now move on to the res directory. Values. Then styles.xml file.
- Add the following lines of code. We are creating a new style theme for our splash screen based on the background xml we created in the drawable folder.
- Let us assign this theme to our “SplashScreen” java class in the androidmanifest.xml.
- In manifests directory open androidmanifest.xml file. Change the launcher activity above the intent filter tag to “.SplashScreen”. And declare your other activities too but without intent filter tag, as shown.
- The last step is to call your main activity, the one you want to show to the user after splash screen is displayed. So, in your SplashScreen.java class, add the following code.
- Splash screen is successfully added, Cheers!