Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom up navigation animation

When back button was clicked:

@Override
public void onBackPressed() {
    finish(); //go back to the previous Activity
    overridePendingTransition(R.anim.slide_in_exit, R.anim.slide_out_exit); 
}

This will animate the views. However how to do that when up navigation button in action bar was clicked?

like image 714
UpCat Avatar asked Dec 22 '13 11:12

UpCat


People also ask

What is popEnterAnim?

The enterAnim and exitAnim is applied when navigating to or from the destination the "regular way", while popEnterAnim is applied to the destination when it is shown as a result of the destination "above" it being popped from the backstack.

What is transition animation in Android?

Activity transitions in material design apps provide visual connections between different states through motion and transformations between common elements. You can specify custom animations for enter and exit transitions and for transitions of shared elements between activities.


2 Answers

cYrixmorten's answer doesn't work well when I want to add some animations to up navigation button, So I override the onOptionsItemSelected method:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch(itemId){
        case android.R.id.home:
            super.onOptionsItemSelected(item);
            this.finish();
            overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
            break;
        default:
            break;
    }

    return true;
}
like image 105
Leonly91 Avatar answered Sep 28 '22 06:09

Leonly91


Put overridePendingTransition in onCreate instead to make the transition happen whenever you leave the activity.

like image 44
cYrixmorten Avatar answered Sep 28 '22 08:09

cYrixmorten