奥利奥(Oreo):禁用活动过渡动画 [英] Oreo: disable Activity transition animation
问题描述
我需要为我的应用程序中的所有屏幕禁用活动过渡动画.先前的解决方案适用于所有Android版本:
I need to disable Activity transition animation for all the screens in my application. Previous solution worked fine for all Android version:
<style name="base_theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowAnimationStyle">@null</item>
</style>
...但是对于Android 8"Oreo",每次转换(前进或后退)都会导致黑屏闪烁. IE.仍然没有任何动画,但是发生了非常烦人的闪烁(90%的机会,约20-30毫秒,整个屏幕).
... but for Android 8 "Oreo" it cause black screen blinking for every transition (forward or back move). I.e. there is still no any animation, but very annoying blinking take place (90% chance, ~20-30 milliseconds, the whole screen).
根据我的研究":
- 它不依赖于活动内容,而是与空的活动一起复制
- 没有任何可以减缓过渡过程的后台工作
- Intent.FLAG_ACTIVITY_NO_ANIMATION也闪烁
- overridePendingTransition(0,0)也不起作用
我能找到的唯一解决方案:
定义一个空的过渡动画
<?xml version="1.0" encoding="utf-8"?>
<set />
并将其应用于应用程序中的每个活动(onCreate& finish)
and apply it to every activity in the application (onCreate & finish)
overridePendingTransition(R.anim.animation_activity_none, R.anim.animation_activity_none);
问题:
这是针对Oreo(即功能),平台错误或应用程序问题的某种新限制吗? 还有其他解决方案吗?
Is it some kind of new restrictions for Oreo (i.e. feature), or platform bug, or maybe the application issue? Are there any other solutions?
[UPDATE]
另一个发现.确保在主线程上调用Activity finish()和overridePendingTransition()对!否则会发生线程争用并且有时不应用overridePendingTransition.
One more finding. Make sure you call Activity finish() and overridePendingTransition() pair on the main thread! Otherwise thread race happens and overridePendingTransition not applied sometimes.
[UPDATE]
Google已经确认这是Android 8.0中的错误,大概是在8.1中修复的. 因此,空动画"修复要持续数年,直到minSdkVersion == 27.
Google has confirmed it's a bug in Android 8.0, presumably fixed in 8.1. So the "empty animation" fix is for years, until minSdkVersion == 27.
推荐答案
我遇到了同样的问题,并且设法解决了这个问题,该想法是什么都不玩,请参见下面的xml:
I had the same issue, and I managed to solve it, the idea is to play nothing, please see the xml below:
值文件夹
<style name="yourTheme">
<item name="android:windowAnimationStyle">@style/ThemeApp.Animation.Activity.Replace</item>
<style name="ThemeApp.Animation.Activity.Replace">
<item name="android:activityOpenEnterAnimation">@anim/replace_anim</item>
<item name="android:activityOpenExitAnimation">@anim/replace_anim</item>
<item name="android:activityCloseEnterAnimation">@anim/replace_anim</item>
<item name="android:activityCloseExitAnimation">@anim/replace_anim</item>
<item name="android:taskOpenEnterAnimation">@anim/replace_anim</item>
<item name="android:taskOpenExitAnimation">@anim/replace_anim</item>
动画文件夹:replace_anim.xml
Anim folder: replace_anim.xml
<set/>
这篇关于奥利奥(Oreo):禁用活动过渡动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!