Skip to content

Instantly share code, notes, and snippets.

@userddssilva
Created April 9, 2021 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save userddssilva/2e5dcd1c0b0ef798ce639fe90c6531c5 to your computer and use it in GitHub Desktop.
Save userddssilva/2e5dcd1c0b0ef798ce639fe90c6531c5 to your computer and use it in GitHub Desktop.
// In your Activity or Fragment create a function as:
fun View.hideKeyboard() {
val inputManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(windowToken, 0)
}
// suppose you have a button with an id your_button_id in XML file related to this Activity or Fragment, so, on button click event:
your_button_id.setOnClickListener{
it.hideKeyboard()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment