To hide other menu items from ActionBar/Toolbar when SearchView is expanded or open you need to apply OnSearchClickListener on it.
On the onCreateOptionsMenu method set OnSearchClickListener like this:-
// hide other menu item when SearchView is open or expanded
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (menu != null) {
menu.findItem(R.id.action_add_reminder).setVisible(false);
menu.findItem(R.id.action_logout).setVisible(false);
}
}
});
Now to reopen or show again the other menu items you need to set the OnCloseListener on the SearchView
// show other menu item when SearchView close
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
// re-show the action button
if (menu != null) {
menu.findItem(R.id.action_add_reminder).setVisible(true);
menu.findItem(R.id.action_logout).setVisible(true);
}
return false;
}
});
0 Comment(s)