How do I dismiss the keyboard when a button is pressed?
Here's a Kotlin solution (mixing the various answers in thread)
Create an extension function (perhaps in a common ViewHelpers class)
fun Activity.dismissKeyboard() {
val inputMethodManager = getSystemService( Context.INPUT_METHOD_SERVICE ) as InputMethodManager
if( inputMethodManager.isAcceptingText )
inputMethodManager.hideSoftInputFromWindow( this.currentFocus.windowToken, /*flags:*/ 0)
}
Then simply consume using:
// from activity
this.dismissKeyboard()
// from fragment
activity.dismissKeyboard()