Blog Infos
Author
Published
Topics
,
Author
Published
Posted by: Nav Singh

Today we will explore Splash screen API which is introduced in Android 12.

Splash screen
  • To make app startup a more consistent and delightful experience android team added a new app launch animation for all apps from the point of launch.
  • It shows the app icon, branding icon(optional), and a transition to the app itself.
  • This new experience brings standard design elements to every app launch.
  • It provides customizable components so apps can maintain their unique branding.
Splash screen components
  1. App icon: It should be a vector drawable, it can be static or animatedMax duration for animations is 1,000 milliseconds. By default, thelauncher icon is used.
  2. App icon background: It is optional. If you need more contrast between the icon and the window background you can use it.
  3. As with adaptive icons, ⅓ of the foreground is masked.
  4. Window background: It consists of a single opaque color. By default, windowbackground color is used if the attribute is not set.
Animations

Splash screen animation consists of 2 animations (enter and exit animations).

  • Enter animation: It consists of the system view to the splash screen. It is controlled by the system and is not customizable.
  • Exit animation: It consists of the animation that hides the splash screen. You can customize it. If you want to do custom animation then you need to remove the splash screen manually when the animation is done.
Customize the splash screen in your app
  • When you try to add any property related to the Splash screen into your default themes.xml, You will get an error because the Splash screen is available only for API 12 or higher .
  • So you need to create a themes.xml under values-v31 directory

You can customize various properties of the Splash screen

Background color 

The background color for the splash screen, if not specify then system will calculate from windowBackground.

<item name="android:windowSplashScreenBackground">#004d28</item>

Animation duration :

Maximum duration should be below 1000ms

<item name="android:windowSplashScreenAnimationDuration">800</item>

Branding icon: It’s optional. It is a drawable image that is placed at the bottom of the starting window.

<item name="android:windowSplashScreenBrandingImage">@drawable/api12_logo</item>

Icon background color :

<item name="android:windowSplashScreenIconBackgroundColor">#004d28</item>

Animated icon :

<item name="android:windowSplashScreenAnimatedIcon">@drawable/your_animated_image</item>
Custom exit animation

You can write your own custom exit animation for the Splash screen.

on API 12 or higher you can get access to Splash screen by calling getSplashScreen() from your Activity.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// custom exit on splashScreen
splashScreen.setOnExitAnimationListener { splashScreenView ->
// custom animation.
ObjectAnimator.ofFloat(
splashScreenView,
View.TRANSLATION_X,
0f,
splashScreenView.width.toFloat()
).apply {
duration = 1000
// Call SplashScreenView.remove at the end of your custom animation.
doOnEnd {
splashScreenView.remove()
}
}.also {
// Run your animation.
it.start()
}
}
}
Show splash screen on-screen for longer periods

Splash screen gets dismissed when app draws its first frame .

  • With the help of ViewTreeObserver.OnPreDrawListener you can suspend the draw of the first frame based on your requirements.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.d("MainActivity", "onCreate: I AM RUNNING ON API 12 or higher")
content.viewTreeObserver.addOnPreDrawListener(object :
ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean =
when {
mainViewModel.mockDataLoading() -> {
content.viewTreeObserver.removeOnPreDrawListener(this)
true
}
else -> false
}
})
}

Job Offers

Job Offers


    Android Engineer

    American Express
    Phoenix, USA
    • Full Time
    apply now

    API Engineer

    American Express
    London
    • Full Time
    apply now

    Mobile Developer Android (m/w/d) Firebase

    REWE digital
    Köln / Cologne
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

Jobs

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Splash screen is the initial screen you’ll see when you open your app. It…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu