Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar up button transition effect

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

like image 388
dominguesgm Avatar asked Jul 25 '13 09:07

dominguesgm


2 Answers

@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>
like image 122
Philip Herbert Avatar answered Oct 07 '22 15:10

Philip Herbert


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;
}
like image 21
An-droid Avatar answered Oct 07 '22 14:10

An-droid