如何在Android中切换没有动画的活动? [英] How to switch activity without animation in Android?

查看:99
本文介绍了如何在Android中切换没有动画的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在AndroidManifest文件中正确使用Intent标志FLAG_ACTIVITY_NO_ANIMATION?我认为我的问题微不足道,但是我找不到很好的例子或解决方案.

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>

但是,编译器未报告任何错误,但data是不正确的. 我只想禁用动画,以防在活动之间进行切换.我可以在onCreate或onResume中使用getWindow().setWindowAnimations(0);,但是使用标志是更好的方法,不是吗?

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?

我也可以在代码中使用

    Intent intent = new Intent(v.getContext(), newactivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    getContext().startActivity(intent);

但是我想在Android清单中使用此标志.在从第二个活动返回到第一个活动的情况下,也要禁用动画.

But I want to use this flag in Android Manifest. To disable animation also in case returning from second activity to first.

推荐答案

您可以创建样式

 <style name="noAnimTheme" parent="android:Theme">
   <item name="android:windowAnimationStyle">@null</item>
</style>

并将其设置为清单中您的活动的主题:

and set it as theme for your activity in the manifest:

   <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
    </activity>

您还可以定义样式以指定自定义进入和退出动画. http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

You can also define a style to specify custom entry and exit animations. http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

这篇关于如何在Android中切换没有动画的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆