Activity Transition Animations in Android

对着背影说爱祢 提交于 2019-11-28 12:34:22

To define an animation when the user presses the back button, you have to override onBackPressed() in your Activity and use overridePendingTransition() in there:

public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
}

So this animation will only be shown when the back button gets pressed.

To set an animation when a new Activity opens, you just have to define the animation after you called startActivity() or similar:

startActivity(some_intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);

you have use default animation in android activity overridePendingTransition

startActivity(new Intent(getApplicationContext(),Login.class));
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!