Android中如何切换没有动画的Activity?
如何在AndroidManifest文件中正确使用Intent标志FLAG_ACTIVITY_NO_ANIMATION
?我认为我的问题很微不足道,但我找不到好的例子或解决方案。
<intent-filter>
<data android:name="android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION" />
</intent-filter>
然而,编译器没有报告错误,但 data
不正确。 我只想在活动之间切换时禁用动画。我可以在 onCreate 或 onResume 中使用 getWindow().setWindowAnimations(0);
但使用 flag 是更好的方法,不是吗?
我也可以在代码中使用:
Intent intent = new Intent(v.getContext(), newactivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
getContext().startActivity(intent);
但我想在 Android Manifest 中使用这个标志。在从第二个活动返回到第一个活动的情况下也禁用动画。
How can I use properly the Intent flag FLAG_ACTIVITY_NO_ANIMATION
in AndroidManifest file? I supose my problem is trivial, but I can't find good example or solution to it.
<intent-filter>
<data android:name="android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION" />
</intent-filter>
However no error is reported by compliator, but data
isn't correct.
I just want to disable animation in case switching between activities. I can use getWindow().setWindowAnimations(0);
in onCreate or onResume rather but using flag is better way, isn't it?
I can use also in code:
Intent intent = new Intent(v.getContext(), newactivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
getContext().startActivity(intent);
But I want to use this flag in Android Manifest. To disable animation also in case returning from second activity to first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以创建样式,
并将其设置为清单中活动的主题:
您还可以定义样式来指定自定义进入和退出动画。
http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation< /a>
You can create a style,
and set it as theme for your activity in the manifest:
You can also define a style to specify custom entry and exit animations.
http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation
如果您的上下文是一个 Activity,您可以调用 overridePendingTransition:
因此,以编程方式:
If your context is an activity you can call overridePendingTransition:
So, programmatically:
试试这个代码,
Try this code,
您也可以在您不想从中转换的所有活动中执行此操作:
我喜欢这种方法,因为您不必打乱活动的风格。
You can also just do this in all the activities that you dont want to transition from:
I like this approach because you do not have to mess with the style of your activity.
主题风格中的线条效果很好,但用白屏代替了动画。尤其是在速度较慢的手机上 - 这真的很烦人。
因此,如果您想要即时过渡 - 您可以在主题样式中使用它:
The line in the theme style works fine, yet that replaces the animation with a white screen. Especially on a slower phone - it is really annoying.
So, if you want an instant transition - you could use this in the theme style:
这是一个单行解决方案,适用于低至
minSdkVersion 14
的版本,您应该将其插入res/styles.xml
中:如下所示:
干杯!
Here is a one-liner solution that works for as low as
minSdkVersion 14
which you should insert in youres/styles.xml
:like so:
Cheers!
启动意图后,您可以使用此代码:
如果使用,意图将在没有动画或过渡的情况下工作
After starting intent you can use this code :
If used, intent will work with no animations or transitions
这不是示例使用或解释如何使用
FLAG_ACTIVITY_NO_ANIMATION
,但它确实回答了如何禁用Activity
切换动画,如问题标题中所述:Android,如何禁用开始新活动时有“擦除”效果吗?
This is not an example use or an explanation of how to use
FLAG_ACTIVITY_NO_ANIMATION
, however it does answer how to disable theActivity
switching animation, as asked in the question title:Android, how to disable the 'wipe' effect when starting a new activity?
创建您自己的样式覆盖 android:Theme
然后在清单中使用它,如下所示:
create your own style overriding android:Theme
Then use it in manifest like this: