Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 957
Marta Rodriguez Avatar asked Nov 25 '14 11:11

Marta Rodriguez


People also ask

How do I get the back button on my Toolbar?

Show back button using actionBar. setDisplayHomeAsUpEnabled(true) this will enable the back button. Custom the back event at onOptionsItemSelected. This will enable the back function to the button on the press.

How do I get rid of the back arrow on my android Toolbar?

getActionBar(). setDisplayShowHomeEnabled(false); //disable back button getActionBar(). setHomeButtonEnabled(false); In a older android phone, the back button is removed with these two code lines.

How do I replace my action bar Toolbar?

You'll want to add android:fitsSystemWindows="true" to the parent layout of the Toolbar to ensure that the height of the activity is calculated correctly. When using the support library, make sure that you are importing android. support. v7.


1 Answers

Use  

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

 

to achieve this.

You can create your own close icon or get from material design icon set on GitHub. Also, add this line before above line to make close function as the back arrow.

this.getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
like image 154
Alok Nair Avatar answered Oct 06 '22 00:10

Alok Nair