What is a Splash screen?
Splash screens (also known as launch screens) provide a simple initial experience while your mobile app loads. They set the stage for your application while allowing time for the app engine to load and your app to initialize.
Example:
When a user launches an app, the following events occur -
The system shows the splash screen using themes and any animations that you've defined.
When the app is ready, the splash screen is dismissed and the app is displayed.
The elements of the animation are defined by XML resource files in the Android Manifest. There are light and dark mode versions for each.
Elements and mechanisms of animation
The app icon (1) above should be a vector drawable, and it can be static or animated. Although animations can have an unlimited duration, it is recommended that it doesn't exceed 1,000 milliseconds. By default, the launcher icon is used.
The icon background (2) above is optional and is useful if more contrast is needed between the icon and the window background. If you use an adaptive icon, its background is displayed if there is enough contrast with the window background.
As with adaptive icons, ⅓ of the foreground is masked (3) above.
The window background (4) above consists of a single opaque color. If the window background is set and is a plain color, it is used by default if the attribute is not set.
Customize splash screen
By default, SplashScreen uses the windowBackground of your theme if it's a single color and the launcher icon.
The customization of the splash screen is done by adding attributes to the app theme.
Your app's splash screen can be customized in any of the following ways:
- Setting theme attributes to change its appearance
- Keeping it on-screen for a longer period
- Customizing the animation for dismissing the splash screen
Theme to change the appearance -
Use windowSplashScreenBackground to fill the background with a specific single color:
Use windowSplashScreenAnimatedIcon to replace an icon in the center of the starting window. If the object is animatable and drawable through AnimationDrawable and AnimatedVectorDrawable, it will also play the animation while showing the starting window.
Optionally, you can use windowSplashScreenBrandingImage to set an image to be shown at the bottom of the splash screen.
Change time period for splash screen
The splash screen is dismissed as soon as your app draws its first frame.
If you need to load a small amount of data such as in-app theme settings from a local disk asynchronously, you can use ViewTreeObserver.OnPreDrawListener to suspend the app to draw its first frame.
Animation for dismissing splash screen
You can further customize the animation of the splash screen through Activity.getSplashScreen
Depending on the duration of the app launch, the drawable might be in the middle of its animation. Use SplashScreenView.getIconAnimationStartMillis to know when the animation started.
Make your own Splash screen
Create a new Activity SplashActivity.java and make its XML the way you want your splash screen to be. Edit the activity as this in your manifest XML file.
Add an intent to go to your main activity inside your splashActivity.java file.
The end
If you liked this make sure to give a follow.