I\'ve searched half a dozen other answers on SO, but haven\'t found one that works. All I\'m trying to do is dismiss the soft keyboard when the user presses the enter butto
This is what worked for me. Based on this layout xml:
I needed to do this for the keyboard to dismiss and the text into to lose focus and hide the cursor.
findViewById(R.id.ip_override_text_input_sat).setOnKeyListener { v, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_ENTER && currentFocus != null) {
val inputManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(
this.currentFocus!!.windowToken,
HIDE_NOT_ALWAYS
)
currentFocus!!.clearFocus()
return@setOnKeyListener true
}
return@setOnKeyListener false
}
Hope this helps someone doing the same