简体   繁体   English

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

[英]AnimatedVectorDrawable as Window background. Is it possible?

I'm trying to use AnimatedVectorDrawable as a splash animation placed in the window background. 我正在尝试使用AnimatedVectorDrawable作为放置在窗口背景中的初始动画。 I use the official example given in https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html . 我使用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? Window背景中的动画是否可能?

The first screen that you see when opening an app for the first time (cold start) is a screen placeholder create by the WindowManager . 第一次打开应用程序时看到的第一个屏幕(冷启动)是由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. 要启动窗口背景的动画,您必须调用其start()方法,但WindowManager是一个您几乎无法控制的系统服务。 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. 因此,在应用程序初始化的这个阶段,除非在Application.onCreate()方法中有一些模糊的方法来控制WindowManager ,否则无法为矢量背景设置动画。

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. 很少有人在主要活动的onCreate冷启动后制作动画。

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 在AndroidManifest.xml中的启动活动中将属性android:windowBackground的主题设置为静态drawable
  2. Before call super.onCreate() in your Activity, change the theme for your default theme. 在调用Activity中的super.onCreate()之前,请更改默认主题的主题。
  3. Set a content view with a ImageView of your AnimatedVectorDrawable at the same position of your static window background vector. 使用AnimatedVectorDrawable的ImageView在静态窗口背景向量的相同位置设置内容视图。
  4. Call start() method of your AnimatedVectorDrawable. 调用AnimatedVectorDrawable的start()方法。

Here is an AndroidDeveloper's post explaining in details how to deal with application themes for launch screens 这是AndroidDeveloper的帖子,详细解释了如何处理启动屏幕的应用程序主题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序在后台运行时,无法收到地理围栏通知。 - Geofence Notification not get when app is in background. 应用程序在后台时显示图标。 Android的 - Show icon while app is in background. Android 无法启动接收器,应用程序在后台。 AlarmReceiver 触发通知 - Unable to start receiver, app is in the background. AlarmReceiver to fire Notification 以自定义背景在“文本视图”中以45度显示文本。 - Displaying text at 45 degree in Text View, with a custom background. 应用程序被杀死或后台运行时,FCM导航无法正常工作。 - FCM Navigation not working while app was killed or background. 当应用程序处于后台时更新UI。 取消注册BroadcastReceiver - Update UI when app is in background. Unregister BroadcastReceiver 蓝牙通信在背景中。 线程,服务,IntentService,AsyncTask ..? - Bluetooth Communication in Background. Thread, Service, IntentService, AsyncTask..? 是否有可能使当前窗口的内容进入后台服务 - Is it possible to get the content of current window into a background service 如何从xml布局背景中删除空格。 - how to remove the space form xml layout background.? Android:在后台重复执行任务。 我的方法正确吗? - Android: Repeat tasks in background. Does my approach is correct?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM