关闭软键盘
1.Fragment中关闭
1 fun Fragment.hiddenKeyboard(v : View){ 2 val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 3 imm.hideSoftInputFromWindow(v.getWindowToken(), 0) 4 }
给Fragment扩展一个函数,其中v是有焦点的 EditText
2.Activity中关闭
1 fun Activity.hiddenKeyboard(){ 2 val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 3 imm.hideSoftInputFromWindow(getWindow()?.getDecorView()?.getWindowToken(), 0/*InputMethodManager.HIDE_NOT_ALWAYS*/) 4 }