Disable activity slide-in animation when launching new activity?

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

I have an activity which launches another activity, via a button click. By default, on newer OS versions of android, the OS will animate the new activity sliding in from right to left.

Is there a way to disable this animation? I just want the new activity to appear without any sort of animation.

回答1:

The FLAG_ACTIVITY_NO_ANIMATION flag works fine for disabling the animation when starting activities.

To disable the similar animation that is triggered when calling finish() on an Activity, i.e the animation slides from right to left instead, you can call overridePendingTransition(0, 0) after calling finish() and the next animation will be excluded.

This also works on the in-animation if you call overridePendingTransition(0, 0) after calling startActivity(...).



回答2:

IMHO this answer here solve issue in the most elegant way..

Developer should create a style,

then in manifest set it as theme for activity or whole application.

Voila! Nice and easy..

p.s. credits to original author please..



回答3:

Apply

startActivity(new Intent(FirstActivity.this,SecondActivity.class));

then

overridePendingTransition(0, 0);

This will stop the animation.



回答4:

Just specify Intent.FLAG_ACTIVITY_NO_ANIMATION flag when starting



回答5:

In my opinion the best answer is to use "overridePendingTransition(0, 0);"

to avoid seeing animation when you want to Intent to an Activity use:

this.startActivity(new Intent(v.getContext(), newactivity.class)); this.overridePendingTransition(0, 0);

and to not see the animation when you press back button Override onPause method in your newactivity

@Override protected void onPause() {     super.onPause();     overridePendingTransition(0, 0); }


回答6:

This works for me when disabling finish Activity animation.

@Override protected void onPause() {     super.onPause();     overridePendingTransition(0, 0); }


回答7:

I'm on 4.4.2, and calling overridePendingTransition(0, 0) in the launching activity's onCreate() will disable the starting animation (calling overridePendingTransition(0, 0) immediately after startActivity() did NOT work). As noted in another answer, calling overridePendingTransition(0, 0) after finish() disables the closing animation.

Btw, I found that setting the style with "android:windowAnimationStyle">@null (another answer mentioned here) caused a crash when my launching activity tried to set the action bar title. Debugging further, I discovered that somehow this causes window.hasFeature(Window.FEATURE_ACTION_BAR) to fail in the Activity's initActionBar().



回答8:

FLAG_ACTIVITY_NO_ANIMATION may work, but wasn't doing the trick for me when combined with FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK. I'm apparently seeing the animation for creating a new task with a fresh activity stack as I navigate laterally to my other top-level views.

What did work here was calling "overridePendingTransition(0, 0);" either immediately after my startActivity() call or the onPause(). Both ways worked, but doing it after startActivity() gives me a little more control over when I want animations and when I don't.



回答9:

I had a similar problem of getting a black screen appear on sliding transition from one activity to another using overridependingtransition. and I followed the way below and it worked

1) created a noanim.xml in anim folder

     

and used

overridePendingTransition(R.drawable.lefttorightanim, R.anim.noanim);

the first parameter as my original animation and second parameter which is the exit animation as my dummy animation



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!