Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 334
WindRider Avatar asked Aug 09 '17 20:08

WindRider


People also ask

How do I make an animated splash screen?

Go to app > java > first package name > right-click > New > Activity > Empty Activity and create another activity and named it as SplashScreen. Edit the activity_splash_screen. xml file and add image, text in the splash screen as per the requirement.

What is window background?

android:background is the background color (drawable to be precise) of a view component whereas android:windowBackground is the background color of the window (activity or dialog) in which your view resides.


1 Answers

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

like image 136
Allan Veloso Avatar answered Sep 22 '22 14:09

Allan Veloso