How to hide Android soft keyboard on EditText

前端 未结 16 1124
长发绾君心
长发绾君心 2020-11-27 14:38

I have an Activity with some EditText fields and some buttons as a convenience for what normally would be used to populate those fields. However when we the user touches on

16条回答
  •  隐瞒了意图╮
    2020-11-27 15:19

    Simply use below method

    private fun hideKeyboard(activity: Activity, editText: EditText) {
        editText.clearFocus()
        (activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(editText.windowToken, 0)
    }
    

提交回复
热议问题