控制软键盘弹出和隐藏
protected fun showKeyboard(isShow: Boolean , view :EditText ) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
if (isShow) {
view.setFocusable(true)
view.setFocusableInTouchMode(true)
view.requestFocus()
if (view == null) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
} else {
imm.showSoftInput(view, 0)
}
} else {
if (view != null) {
imm.hideSoftInputFromWindow(view!!.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
}
}
}
edittext 获取焦点
EditText.setFocusable(true);
EditText.setFocusableInTouchMode(true);
EditText自动获取焦点并弹出键盘
EditText.setFocusable(true);
EditText.setFocusableInTouchMode(true);
EditText.requestFocus();