您好我想做下一件事:当我点击EditText时,我想隐藏键盘但看到光标。我试着这样做:
editText_test!!.setCursorVisible(false);
editText_test!!.setFocusableInTouchMode(false);
editText_test!!.setFocusable(true);
显然我没有看到键盘,但我无法点击我的EditText。我怎样才能做到这一点 ?确切地说,我正在使用Kotlin。
谢谢!
答案 0 :(得分:4)
如果您的最低 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
}
答案 1 :(得分:0)
为您的EditText的onFocus设置一个监听器,您可以添加:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
How to avoid automatically appear android keyboard when activity start
答案 2 :(得分:0)
强制android使用hideSoftInputFromWindow
中的InputMethodManager方法隐藏虚拟键盘View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
答案 3 :(得分:0)
在清单文件中尝试此操作
:
<activity
...
android:windowSoftInputMode="stateHidden|adjustResize"
...
>