Im using an action bar and adding a searchView to it. I have implemented the searchView.onCLoseListener but this does not seem to be getting invoked. Any suggestions ?
MenuItemCompat.OnActionExpandListener expandListener = new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when action item collapses
/*Hiding the mic on search visibility*/
myMenu.findItem(R.id.action_speak).setVisible(false);
Log.v("test","colllapse");
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
Log.v("test","expand");
return true; // Return true to expand action view
}
};
//Searchview Initilisation
MenuItem searchViewItem = menu.findItem(R.id.action_search);
// Assign the listener to that action item
MenuItemCompat.setOnActionExpandListener(searchViewItem, expandListener);
More info from here: https://developer.android.com/training/appbar/action-views.html