Skip to content

Instantly share code, notes, and snippets.

@yoosinpaddy
Created April 5, 2022 22:12
Show Gist options
  • Save yoosinpaddy/e6ab555d7340effd9e9e0083e2ecfb20 to your computer and use it in GitHub Desktop.
Save yoosinpaddy/e6ab555d7340effd9e9e0083e2ecfb20 to your computer and use it in GitHub Desktop.
Hide Keyboard Kotlin
fun hideKeyboard(activity: Activity) {
val imm: InputMethodManager =
activity.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
//Find the currently focused view, so we can grab the correct window token from it.
var view = activity.currentFocus
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = View(activity)
}
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment