控制軟鍵盤彈出和隱藏
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();