更改 ActionBar 隐藏动画?
默认情况下,在 Android 3.0+ 中,当调用 ActionBar.hide()/show() 时,栏会以短暂的淡入/淡出动画进行动画处理。
似乎没有与动画资源关联的 XML 样式属性 此列表中 。
有什么办法可以改变这个动画吗?就我而言,我只是想更改动画时间,但是是否也可以有滑动动画?
By default in Android 3.0+, when ActionBar.hide()/show() are called the bar is animated with a brief fade in/out animation.
There does not seem to be an XML style attribute in this list associated with an animation resource.
Is there some way to change this animation? In my case, I simply want to change the animation time, but is it also possible to have a sliding animation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不会。
至少在 3.0、3.1 或 3.2 中不会。如果您查看 com.android.internal.app.ActionBarImpl 的反编译源代码,您会发现动画是硬编码的。
例如,从 3.2 开始:
更新
ICS 和 JellyBean 也是如此
No.
At least not in 3.0, 3.1, or 3.2. If you look at the decompiled sources of
com.android.internal.app.ActionBarImpl
you'll find that the animations are hard-coded.E.g., from 3.2:
UPDATE
Same goes for ICS and JellyBean
禁用 ActionBar 动画的 hack(通过检查源代码发现)可以通过内省来完成:
当然是丑陋的,但这实际上是有效的,至少从 Android v4.2 开始是这样。
A hack for disabling the ActionBar animation (found by inspecting the source code) can be done through introspection via:
Ugly, of course, but this actually work, at least from Android v4.2.
这两种解决方案都不适合我,所以我尝试完全禁用动画:
它对我来说效果很好。您可以尝试对整个操作栏视图组进行动画处理以达到类似的效果。
Neither of solutions doesn't work for me so I try this to disable animation at all:
And it works just fine for me. You can try to animate whole action bar viewGroup to achieve similar effect.
是的,你当然可以。
首先,您可以像这样获得 ActionBar 视图:
然后您可以直接在视图上应用动画,如下所示:
Yes, you most certainly can.
You first get the ActionBar view like this:
Then you can apply animations directly on the view like this: