Android SearchView Hide keyboard at startup

I have a small problem that I am trying to solve. When I open the application, a request for viewing request appears on the keyboard. However, I just want the keyboard to appear when I click on search. How to fix it?

Thank!

+5
source share
6 answers

It worked for me.

/ * Code used to hide focus * /

searchView =(SearchView)view.findViewById(R.id.searchView);
searchView.setFocusable(false);
+7
source

Use these attributes in the layout tag in the XML file:

android:focusable="true"
android:focusableInTouchMode="true"

or in the xml manifest for your action add a property:

android:windowSoftInputMode="stateAlwaysHidden"
+6
source

:

searchView =(SearchView)view.findViewById(R.id.searchView);
searchView.clearFocus();
+3

This is work for me: clear focus in onResume () activity or fragment

objSearchView=(SearchView)view.findViewById(R.id.searchView);

 @Override
    public void onResume() {
        super.onResume();
        objSearchView.clearFocus();
    }
+3
source

for me i have to call both setFocusable (false) and clearFocus ()

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        . . .
        searchView = (SearchView) findViewById(R.id.search_view);
        searchView.setFocusable(false);
        . . .
    }

@Override
    protected void onResume() {
        super.onResume();
        . . .
        searchView.clearFocus();
        . . .
    }
0
source

Make sure you are not using this:

searchInput = (SearchView) layout.findViewById(R.id.search);
searchInput.onActionViewExpanded();//<<<<------------------ don't use it.
0
source

Source: https://habr.com/ru/post/1628024/


All Articles