Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide soft keyboard on application load

I have an application with an EditText element on the main view. This means that when my application is loaded the soft keyboard appears per default.

I would like to be able to hide the keyboard on load, so it does not show until i tap on the EditText view.

How do i manage this?

like image 695
Esben Andersen Avatar asked May 25 '11 10:05

Esben Andersen


People also ask

How do I hide my soft keyboard?

Hiding the Soft Keyboard Programmatically 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.

Is there any way to dismiss the keyboard programmatically?

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.

How do I hide my keyboard from clicking?

To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);


2 Answers

In your AndroidManifest.xml:

<activity android:name="com.your.package.ActivityName"           android:windowSoftInputMode="stateHidden"  /> 

More details about windowSoftInputMode can be found here.

This setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.

like image 133
inazaruk Avatar answered Sep 21 '22 15:09

inazaruk


You can do something easier. Add this to the LinearLayout (or any other layout that is the root):

<LinearLayout ... android:focusable="true" android:focusableInTouchMode="true" ... /> 
like image 29
neteinstein Avatar answered Sep 21 '22 15:09

neteinstein