2

I want my search view widget to fill the entire toolbar so in menu.xml I did this:

...
app:showAsAction="always"

This seem to hide all other items in the toolbar when search view expands, but not the drawer toggle button:

enter image description here

Is there anyway I can make the search view widget fill the entire toolbar and hide the toggle button too? Thanks

Toni Joe
  • 7,715
  • 12
  • 50
  • 69
  • i think you should use this instead of remove drawer. https://stackoverflow.com/questions/34524290/change-toolbar-color-style-on-searchview-click – Vishal Thakkar Aug 19 '17 at 12:36

1 Answers1

5

You can achieve this by hiding the hamburger button. Set your toolbar navigation icon to null.

toolbar.setNavigationIcon(null);

EDIT

To remove the navigation icon, add the following line in your onCreate method.

getActionBar().setDisplayHomeAsUpEnabled(false);

or

getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);

To make the SearchView fill the action bar, set the width of the SearchView to max in the onCreateOptionsMenu method.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
SearchView searchView = 
(SearchView)menu.findItem(R.id.menu_search).getActionView();
searchView.setMaxWidth(Integer.MAX_VALUE);
Abhi
  • 3,431
  • 1
  • 17
  • 35
  • getSupportActionBar().setDisplayHomeAsUpEnabled(false); and getSupportActionBar().setHomeButtonEnabled(false); or you can try this: toolbar.setNavigationIcon(null); check [here][1] for more details [1]: https://stackoverflow.com/questions/28291001/how-does-one-remove-default-toolbar-menu-items-and-replace-with-different-icons/28291205#28291205 – Ritesh Bhavsar Aug 19 '17 at 12:26