Inflating a screen layout takes some times. On a cold start, it can cause the device to first display a blank screen before the first activity’s layout. A common technique is to use the app’s window background theme to fill this blank screen (eg with a branding icon). In this article, I will go further by showing how to animate this icon.
Your layouts are inflated in a system view called the decor view. It’s this view that you see when the app launches before you first activity’s layout. The technique here is to fill this “blank screen” by styling this view with a drawable.
You have to use a drawable animation but it won’t launch alone, the trick here is to programmatically access the decor view to start it.
Define a drawable animation to use as background
Use it as window background theme in a specific style
In the manifest, configure your splash screen activity to use it
In your splash screen activity, recover the animation from the Decor View and start it
A sample app is available on my github, happy reviewing :)
jacquesgiraudel/AnimatedSplashScreen_AnimatedSplashScreen - Sample app for an animated splashscreen (without blank screen on cold starts)_github.com
References :
Android Developer at jacquesgiraudel.com