Created
April 5, 2022 22:12
-
-
Save yoosinpaddy/e6ab555d7340effd9e9e0083e2ecfb20 to your computer and use it in GitHub Desktop.
Hide Keyboard Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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