I have a MainActivity with callbacks implementation of:
I just found a new solution that worked for me very clean, maybe someone else is interested:
In the open/close implementation of the Drawer I call directly onPrepareOptionsMenu(mMenu)
instead of invalidateOptionsMenu()
.
As you see, I use the instance of the menu saved in mMenu at its creation. Calling this method I avoid to invalidate the searchView, that still could contain some text, therefore not to be cleared.
Here another trick (always inside onPrepareOptionsMenu
) to clear/iconify the searchView I check if currently a searchText is previously set in my Service class:
if (!Service.getInstance().hasSearchText()) {
Log.d(MainActivity.class.getSimpleName(), "onPrepareOptionsMenu Clearing SearchView!");
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setIconified(true);// This also clears the text in SearchView widget
}