Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView focused when hiding the ActionBar menu

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;
    }
like image 391
juliusspencer Avatar asked Sep 30 '11 00:09

juliusspencer


People also ask

How to set SearchView in Android studio?

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.


2 Answers

try calling mSearchView.clearFocus() on your initialization of the searchView. That worked for me when I had a similar problem.

like image 122
jfrey Avatar answered Oct 04 '22 22:10

jfrey


try call setFocusable(false) on SearchView when you init it.

like image 26
barbucha Avatar answered Oct 04 '22 22:10

barbucha