hyrulelink16
hyrulelink16

Reputation: 389

Toolbar Back Animation

I made a transition animation from one activity to another via clickListener. Now I want to add it on the back button of the Toolbar to go back. I already set the parent activities, but I have no idea how to implement animation on the back button.

enter image description here

Upvotes: 1

Views: 787

Answers (1)

Umesh Singh Kushwaha
Umesh Singh Kushwaha

Reputation: 5741

Override the onBackPressed() method and apply your transition and call finish. To handle toolbar back click event override following method.

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    if (menuItem.getItemId() == android.R.id.home) {
        onBackPressed();
    }
    return super.onOptionsItemSelected(menuItem);
}

Upvotes: 3

Related Questions