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)
}