How to display icon with back arrow in android toolbar like WhatsApp ?
I use below code to set back arrow & icon in toolbar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
toolbar.setLogo(icon);
but i got result as below image.
I want icon immediate next after back arrow. I don't want any gap between back arrow & icon like below image of WhatsApp.
How to set icon with back arrow in toolbar like WhatsApp ?
you can't do this with the normal back arrow in toolbar because it has a minWidth 56dp with scaleType center you can do something like this:
and handle ibCustomBack by your self.
Well I think you should try to do some edits in back-button image like apply some conciseness reduce image width and also making it transparent. May be helpful
along with
You can set the padding of the Home Icon using the below code
It seems like you need to set three of the action bar related values to display the icon:
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(R.drawable.ic_cast_dark);
I would have thought that
setDisplayHomeAsUpEnabled' and 'setIcon
should have been enough but seems not.I am using android.support.v7.app.ActionBar
As far as I Know, WhatsApp is not using App-compat Support Library Toolbar, Whatsapp is setting the Custom Action Bar using
Attached is the conversation_actionbar.xml , Whatsapp is using
But I would suggest you to follow Materail Design Rules and use ToolBar of App-compat Support Library,
You can get the following result as shown in the Picture below
By using following code
your_activity.xml:
toolbar_conversation.xml:
Activity.java
Just wait for it, Whatsapp will shift to App-compat Support Library in future.