I currently have a SearchView in the action bar of my app. When I click the search icon, the SearchView expands and the keyboard pops up as expecte
My way:
public class CustomSearchView extends SearchView{
public CustomSearchView(final Context context) {
super(context);
this.setIconifiedByDefault(true);
}
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK &&
event.getAction() == KeyEvent.ACTION_UP) {
this.onActionViewCollapsed();
}
return super.dispatchKeyEventPreIme(event);
}
}
CustomSearchView searchView = (CustomSearchView)menu.findItem(R.id.menu_search).getActionView();