hide keyboard suggestion android kotlin
Hide Keyboard in Android using Kotlin
fun hideKeyboard(activity: Activity) {
val inputMethodManager = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
val currentFocus = activity.currentFocus
currentFocus?.let {
inputMethodManager.hideSoftInputFromWindow(it.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
}
}
This Kotlin function can be used to hide the keyboard in an Android application. It takes an Activity
as a parameter and uses the InputMethodManager
to hide the soft keyboard from the current focused view. If the currentFocus
is not null, the function hides the soft input from the window associated with the currentFocus
view.