Splash screen in Android

Splash screen in Android

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:

image.png

When a user launches an app, the following events occur -

  1. The system shows the splash screen using themes and any animations that you've defined.

  2. 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

image.png

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:

  1. Setting theme attributes to change its appearance
  2. Keeping it on-screen for a longer period
  3. Customizing the animation for dismissing the splash screen

Theme to change the appearance -

  1. Use windowSplashScreenBackground to fill the background with a specific single color: image.png

  2. 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. image.png

  3. Optionally, you can use windowSplashScreenBrandingImage to set an image to be shown at the bottom of the splash screen. image.png

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. image.png

Animation for dismissing splash screen

You can further customize the animation of the splash screen through Activity.getSplashScreen image.png

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. image.png

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. image.png

Add an intent to go to your main activity inside your splashActivity.java file. image.png

The end

If you liked this make sure to give a follow.