35

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?

inazaruk
  • 74,247
  • 24
  • 188
  • 156
Esben Andersen
  • 802
  • 2
  • 9
  • 18

3 Answers3

29

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"
...
/>
Devrath
  • 42,072
  • 54
  • 195
  • 297
neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • 3
    The accepted answer didn't work for me, I already had stateHidden set. This suggestion works. I applied it to the XML layout instead: android:focusable="true" and android:focusableInTouchMode="true" on a parent view group. – James Wald Jan 05 '12 at 22:49
5
InputMethodManager imm = 
    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This will hide in all situations (even when the EditView has focus):

 EditText editView = (EditText) findViewById(R.id.editTextConvertValue);
 editView.setInputType(InputType.TYPE_NULL);
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
John Cooper
  • 7,343
  • 31
  • 80
  • 100
1

You can hide keyboard when page open easily

Add these two properties on root layout

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

Sample code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true">
Rahul Raj
  • 1,010
  • 9
  • 10