Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created May 16, 2018 16:30
Show Gist options
  • Save EmmanuelGuther/60443186eaa573a91e700429039973b1 to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/60443186eaa573a91e700429039973b1 to your computer and use it in GitHub Desktop.
Kotlin extension function to hide keyboard if it is being shown
fun AppCompatActivity.hideKeyBoard(){
val view = this.currentFocus
if (view != null) {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment