Marta Rodriguez Marta Rodriguez - 3 months ago 45
Android Question

Material "close" button in Toolbar instead of Back

I have seen in Google's Inbox App, composing a new email, in the toolbar instead of the back button (an arrow) it has a "close" button (see picture).

How can I achieve this?

inbox compose close button

Answer

Use  

this.getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_close);

 

to acheive this.

You can create your own close icon or get from material design icon set on github. Also add this to make close function as back arrow.

this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);