Casper Lindberg
Casper Lindberg

Reputation: 680

Android SearchView Hide Keyboard on Start up

I'm having a minor issue I'm trying to solve. When I open my application, the keyboard shows to enter a query for the search view. However I just want the keyboard to appear when I click on the search view. How do I fix this?

Thanks!

Upvotes: 14

Views: 9421

Answers (7)

damith alahakoon
damith alahakoon

Reputation: 270

This works for me I used to this code Hide Keyboard and show a hint

 searchView =(SearchView)view.findViewById(R.id.searchView);
    
    searchView .setIconified(false);
    searchView .clearFocus();

Upvotes: 0

M.Namjo
M.Namjo

Reputation: 522

Make sure you do not use this:

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

Upvotes: 0

Dev
Dev

Reputation: 857

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();
        . . .
    }

Upvotes: 0

Vrajesh
Vrajesh

Reputation: 1332

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

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

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

Upvotes: 5

kara4k
kara4k

Reputation: 407

This works for me:

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

Upvotes: 6

This worked for me.

/* Code used to hide focus */

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

Upvotes: 10

Stanojkovic
Stanojkovic

Reputation: 1632

Use this attributes in your layout tag in XML file:

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

or in manifest xml for your Activity add the property:

android:windowSoftInputMode="stateAlwaysHidden"

Upvotes: 7

Related Questions