Search code examples
androidanimationandroid-vectordrawableanimatedvectordrawable

AnimatedVectorDrawable as Window background. Is it possible?


I'm trying to use AnimatedVectorDrawable as a splash animation placed in the window background. I use the official example given in https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html. It appears but doesn't animate.

Are animations in a Window background possible at all?


Solution

  • The first screen that you see when opening an app for the first time (cold start) is a screen placeholder create by the WindowManager. It creates the placeholder by getting resources that you set on your theme, like the window background and status bar color. To start the animation of your window background you have to call its start() method, but the WindowManager is a system service that you have little or no control over. So on this phase of application initialisation, unless there is some obscure way to control the WindowManager in the Application.onCreate() method, it is not possible to animate the vector background.

    I opened from cold start a lot of my apps including Google ones and not a single one seems to implement animations on the cold start phase (like the docs of Material Design imply possible). A very few make animations after the cold start at the onCreate of the main activity.

    If it's not a problem start the animation after he cold start, like in the case of moving the logo to the top of the screen, you can:

    1. Set a theme with attribute android:windowBackground to your static drawable at your launch activity in AndroidManifest.xml
    2. Before call super.onCreate() in your Activity, change the theme for your default theme.
    3. Set a content view with a ImageView of your AnimatedVectorDrawable at the same position of your static window background vector.
    4. Call start() method of your AnimatedVectorDrawable.

    Here is an AndroidDeveloper's post explaining in details how to deal with application themes for launch screens