17

Whenever I click in the EditText the Android keyboard popup window appears, but I don't want the keyboard to pop up.

I want to permanently hide the android keyboard popup for my current application.

How can I do this?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Balaji.K
  • 8,745
  • 5
  • 30
  • 39
  • possible duplicate of [How to close/hide the Android Soft Keyboard?](http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard) – Octavian Helm Jan 30 '11 at 08:07
  • Take a look at this [previous question](http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard) which provides an explanation using [InputMethodManager](http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html). – sahhhm Jan 30 '11 at 08:05
  • I think my solution can help. http://stackoverflow.com/a/21480217/2127930 – cristianomad Jan 31 '14 at 12:40

10 Answers10

28

Setting the flag textIsSelectable to true disables the soft keyboard.

You can set it in your xml layout like this:

<EditText
    android:id="@+id/editText"
    ...
    android:textIsSelectable="true"/>

Or programmatically, like this:

EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);

The cursor will still be present, you'll be able to select/copy/cut/paste but the soft keyboard will never show.

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
12

You may try to fake your EditText with a Button like this:

 <Button
     android:id="@+id/edit_birthday"
     style="@android:style/Widget.EditText"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:hint="@string/hint_birthday"/>
Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • This is better than the other solutions because the keyboard doesn't show at all here. In the other cases, you can see the keyboard popping up for an instance before popping back down. – Anuj Jan 13 '13 at 11:49
  • it does work, but it stays pressed after single tap. how to avoid that? – Iman Akbari Jun 06 '16 at 14:32
  • @ImanAkbari by setting focusable="false", it doesn't stay pressed. – Noel Jan 23 '17 at 20:52
10

In the manifest:

  <activity
        android:name=".YourActivity"
       .
       .
       .
        android:windowSoftInputMode="stateAlwaysHidden" >
   </activity>
SolArabehety
  • 8,467
  • 5
  • 38
  • 42
  • 1
    This appears to only affect if the keyboard is displayed when the activity first gets focus. Per the official documentation, "The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention". It does not suppress the keyboard when pressing the EditText. – Mike Dec 03 '12 at 10:36
7

Works for all Android versions.

In your XML use the property android:textIsSelectable="true"

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    .
    .
    .
    android:textIsSelectable="true"/>

And, in your Java class:

editText1.setShowSoftInputOnFocus(false);

In Kotlin:

editText1.showSoftInputOnFocus = false
Hemendra Sharma
  • 1,063
  • 9
  • 21
5

Solution can be found here :

public void onCreate(Bundle savedInstanceState) {

edittext = (EditText) findViewById(R.id.EditText01);

edittext.setOnEditorActionListener(new OnEditorActionListener() {
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
         if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
            InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
         }
         return false;
      }
   });
}
yohm
  • 452
  • 7
  • 14
0

Try This

 public void disableSoftKeyboard(final EditText v) {
            if (Build.VERSION.SDK_INT >= 11) {
                v.setRawInputType(InputType.TYPE_CLASS_TEXT);
                v.setTextIsSelectable(true);
            } else {
                v.setRawInputType(InputType.TYPE_NULL);
                v.setFocusable(true);
            }
        }
Sagar Badave
  • 121
  • 1
  • 3
  • 9
0

Try to add this in yout onCreate() method.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Not tested but It Should work!!

Paresh P.
  • 6,677
  • 1
  • 14
  • 26
0

In your xml file you can use this:

android:editable="false"
kalabalik
  • 3,792
  • 2
  • 21
  • 50
0

In your xml set attribute editable to false. it won't let you edit the text and the keyboard will not be opened.

<EditText
     android:editable="false"
 />
Marium Jawed
  • 391
  • 4
  • 9
0

These two line should do what you want:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
iTurki
  • 16,292
  • 20
  • 87
  • 132