I have an ActionBar with a SearchView. The hidden/overflow menu items are shown on the right in a drop-down list when the menu button is selected. When the drop-down menu is hidden, the SearchView is focused and the keyboard shows. Is there a way to stop the keyboard from showing (except for the case where the SearchView is touched)?
Regards, Julius.
Edit added code below: Here is how I initialise it:
SearchManager searchManager = (SearchManager) mActivity.getSystemService(Context.SEARCH_SERVICE);
((SearchView) mSearchView).setSearchableInfo(searchManager.getSearchableInfo(mActivity.getComponentName()));
mSearchView.setIconifiedByDefault(mIconified);
mSearchView.setOnQueryTextListener(this);
mSearchView.setOnCloseListener(this);
mSearchView.setFocusable(false);
mSearchView.setFocusableInTouchMode(false);
if(null!=mQuery)
mSearchView.setQuery(mQuery, false);
Edit 2:
Here is what I do when the user wants to start the search:
@Override
public boolean onQueryTextSubmit(String query) {
// Hide keyboard
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(
FragmentActivity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
...
mSearchView.setFocusable(false);
mSearchView.setFocusableInTouchMode(false);
return true;
}
SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
try calling mSearchView.clearFocus()
on your initialization of the searchView. That worked for me when I had a similar problem.
try call setFocusable(false) on SearchView when you init it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With