Reputation: 677
I have 3 activities A,B,C.I am able to show the animations when move the activity from A->B->C.
I want to add the animation when I press the back buton.
I am using overridePendingTransition(R.anim.fadein,R.anim.fadeout) on onCreate() method.
Can some one explain how it works when i pressed the back button?
Upvotes: 0
Views: 846
Reputation: 1504
Override your activity's onBackPressed
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
Upvotes: 1
Reputation: 7295
You have to override back button:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
finish();
overridePendingTransition(R.anim.anim_out, R.anim.anim_in);
return true;
}
return super.onKeyDown(keyCode, event);
}
For exammple: Create "anim" folder in res and add: anim_out:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500" />
</set>
anim_in:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
</set>
Upvotes: 0