Updated 13 December 2023
Android 12 introduces the SplashScreen API which enables a new app launch animation.
Implementation in Android app
We should follow the below points at the time of implementing SplashScreen:-
Note:- The splash screen animation mechanics consist of entering and exit animations.
Enter animation
The enter animation contains the android OS view to the splash screen. The android OS control it and is not customizable.
Exit animation
The exit animation contains the animation run that hides the splash screen. If we want to customize it, we should have access to SplashScreenView.
More about SplashScreenView:-
Customize the splash screen
For customizing the SplashScreen
If we are already using attributes like android:windowBackground, then subsequently we can also use an alternate resource file for Android 12.
1 2 |
<item name="android:windowSplashScreenBackground">@color/...</item> <item name="android:windowSplashScreenAnimatedIcon">@drawable/...</item> |
1 2 |
<item name=”android:windowSplashScreenIconBackground”>@color/...</item> <item name=”android:windowSplashScreenBrandingImage”>@drawable/...</item> |
When the app draws the first frame, the splashscreen will disappear. If we need to load a small amount of data from a local disk asynchronously, we can use ViewTreeObserver.OnPreDrawListener to suspend the app to draw its first frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// Create a new event for the activity. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Set the layout for the content view. setContentView(R.layout.main_activity) // Set up an OnPreDrawListener to the root view. val content: View = findViewById(android.R.id.content) content.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { // Check if the initial data is ready. return if (viewModel.isReady) { // The content is ready; start drawing. content.viewTreeObserver.removeOnPreDrawListener(this) true } else { // The content is not ready; suspend. false } } } ) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ... // Add a callback that's called when the splash screen is animating to // the app content. splashScreen.setOnExitAnimationListener { splashScreenView -> // Create your custom animation. val slideUp = ObjectAnimator.ofFloat( splashScreenView, View.TRANSLATION_Y, 0f, -splashScreenView.height.toFloat() ) slideUp.interpolator = AnticipateInterpolator() slideUp.duration = 200L // Call SplashScreenView.remove at the end of your custom animation. slideUp.doOnEnd { splashScreenView.remove() } // Run your animation. slideUp.start() } } |
Please go through the below links to get more details on Android 12 SplashScreen API:-
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.