SearchView setIconified(false) automatically calls the focus for the searchview. How can I disable this?

rosu alin picture rosu alin · Jul 31, 2015 · Viewed 7.9k times · Source

I have the following code:

  if(mSearchView != null){
        mSearchView.setIconifiedByDefault(false);
        mSearchView.setIconified(false);
        mSearchView.setOnQueryTextListener(this);
        int searchPlateId = mSearchView.getContext().getResources()
                .getIdentifier("android:id/search_plate", null, null);
        View searchPlateView = mSearchView.findViewById(searchPlateId);
        if (searchPlateView != null) {
            searchPlateView.setBackgroundColor(getResources().getColor(R.color.white));
        }
    }

The problem is that the moment I setIconified(false) on the serachview, the keyboard pops up, and I do not want this to happen. Is it possible to prevent this somehow? PS: I Have this in the manifest:

 android:windowSoftInputMode="adjustNothing|stateHidden"

Also do it programmatically in onCreate but no luck

Answer

Lakhan Sharma picture Lakhan Sharma · Jan 20, 2017

Try this:

searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();