AnimatedVectorDrawable作为窗口背景。可能吗?

问题描述 投票:4回答:1

我正在尝试使用AnimatedVectorDrawable作为放置在窗口背景中的水滴动画。我使用https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html中给出的官方示例。它似乎但没有动画。

是否可以在Window背景中制作动画?

android animation android-vectordrawable animatedvectordrawable
1个回答
1
投票

第一次打开应用程序时看到的第一个屏幕(冷启动)是由WindowManager创建的屏幕占位符。它通过获取您在主题上设置的资源(如窗口背景和状态栏颜色)来创建占位符。要开始窗口背景的动画,你必须调用它的start()方法,但WindowManager是一个你很少或根本无法控制的系统服务。因此,在应用初始化的这个阶段,除非在WindowManager方法中有一些模糊的方法来控制Application.onCreate(),否则不可能为矢量背景设置动画。

我从冷启动开始了很多我的应用程序,包括谷歌的应用程序,而不是一个似乎在冷启动阶段实现动画(如材料设计的文档暗示可能)。很少有人在主要活动的onCreate冷启动后制作动画。

如果不是问题,可以在冷启动后启动动画,就像将徽标移动到屏幕顶部一样,您可以:

  1. 在AndroidManifest.xml中的启动活动中将属性为android:windowBackground的主题设置为静态drawable
  2. 在调用Activity中的super.onCreate()之前,请更改默认主题的主题。
  3. 使用AnimatedVectorDrawable的ImageView在静态窗口背景向量的相同位置设置内容视图。
  4. 调用AnimatedVectorDrawable的start()方法。

这是一个AndroidDeveloper's post explaining in details how to deal with application themes for launch screens

© www.soinside.com 2019 - 2024. All rights reserved.