当我点击EditText时如何禁用键盘?

你好我想做的下一件事:当我点击一个EditText我想隐藏键盘,但看到光标。 我试图做到这一点:

editText_test!!.setCursorVisible(false); editText_test!!.setFocusableInTouchMode(false); editText_test!!.setFocusable(true); 

显然我没有看到键盘,但我不能点击我的EditText。 我该怎么做? 准确地说,我正在使用Kotlin。

谢谢 !

如果你有最低的API> = 21

 editText_test!!.showSoftInputOnFocus = false 

处理不同的版本:

 if (Build.VERSION.SDK_INT >= 21) { editText_test!!.showSoftInputOnFocus = false } else if (Build.VERSION.SDK_INT >= 11) { editText_test!!.setRawInputType(InputType.TYPE_CLASS_TEXT) editText_test!!.setTextIsSelectable(true) } else { editText_test!!.setRawInputType(InputType.TYPE_NULL) editText_test!!.isFocusable = true } 

为您的EditText的onFocus设置一个监听器,您可以添加:

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

活动开始时如何避免自动出现android键盘

在listener方法内强制android使用InputMethodManager中的hideSoftInputFromWindow方法隐藏虚拟键盘

 View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } 

在清单文件中试试这个

 : <activity ... android:windowSoftInputMode="stateHidden|adjustResize" ... >