引起键盘关闭时界面卡顿,需在AndroidManifest.xml的<activity>中添加android:windowSoftInputMode="adjustNothing"
AndroidManifest.xml
android:windowSoftInputMode="adjustNothing"
打开软键盘
/**
* 获得焦点并弹出键盘
*/
fun showSoftInputFromWindow(editText: EditText) {
editText.isFocusableInTouchMode = true
editText.requestFocus()
val inputManager = editText.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
inputManager?.showSoftInput(editText, 0)
}
关闭软键盘
/**
* 关闭软键盘
*/
fun closeSoftInput(){
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.hideSoftInputFromWindow(view?.windowToken,0) //界面跳转,关闭键盘
}