I have already created a method for an animation when changing activities when the back button is pressed. The problem is that the actionbar up button has the default transition effect to the previous activity and I can't find a way to override that animation and use a new one. Any ideas? Thanks in advance
Preferably this would be hardcoded in java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
this.finish();
overridePendingTransition(R.anim.fade_in, R.anim.right_slide_out);
}
fade_in.xml (R.anim.fade_in)
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
right_slide_out.xml (R.anim.right_slide_out)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>
Just get the event "home back"
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
overridePendingTransition(R.animator.anim_left, R.animator.anim_right);
return true;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With