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?
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.
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.
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;
}
Put overridePendingTransition in onCreate instead to make the transition happen whenever you leave the activity.
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