Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 274
CoderOgden Avatar asked Feb 09 '16 20:02

CoderOgden


People also ask

How do I hide the keyboard on my Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.

How do I hide the activity on my keyboard?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.

How do I use search view?

Android SearchView provides user interface to search query submitted over search provider. 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.

How to hide keyboard when Click on button in Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 Add the following code to src/MainActivity.java In the above code when you click on the button it will hide keyboard.

How to prevent focus on searchview in Android?

To prevent focus, call searchView.clearFocus on searchView.doOnLayout (using android-ktx)

How to expand menuItem from icon to searchview in Android?

Call MenuItem.expandActionView to expand MenuItem from icon into SearchView. To prevent focus, call searchView.clearFocus on searchView.doOnLayout (using android-ktx)

What is the difference between settext and closekeyboard in Android?

The setText function is invoked when the user clicks the button. It takes the input from edittext and replaces it in the textview. Then it calls the closeKeyboard function and clears the value of edittext. The closeKeyboard function hides the keyboard. MainActivity.java packageorg.geeksforgeeks.gfgHideKey importandroid.content.Context;


2 Answers

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"
like image 89
Stanojkovic Avatar answered Sep 28 '22 11:09

Stanojkovic


This works for me:

searchView =(SearchView)view.findViewById(R.id.searchView);
searchView.clearFocus();
like image 25
kara4k Avatar answered Sep 28 '22 11:09

kara4k