Hiding the android keyboard for EditText

2019-01-25 06:22发布

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?

9条回答
Root(大扎)
2楼-- · 2019-01-25 06:28

These two line should do what you want:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
查看更多
再贱就再见
3楼-- · 2019-01-25 06:29

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;
      }
   });
}
查看更多
萌系小妹纸
4楼-- · 2019-01-25 06:38

Try to add this in yout onCreate() method.

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

Not tested but It Should work!!

查看更多
劫难
5楼-- · 2019-01-25 06:44

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
查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-25 06:45

In your xml file you can use this:

android:editable="false"
查看更多
叼着烟拽天下
7楼-- · 2019-01-25 06:47

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.

查看更多
登录 后发表回答