Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created May 16, 2018 15:37
Show Gist options
  • Select an option

  • Save EmmanuelGuther/b90de6d66c03e7e94dcf149dfed88646 to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelGuther/b90de6d66c03e7e94dcf149dfed88646 to your computer and use it in GitHub Desktop.
Extension function to hide or show keyboard
fun AppCompatActivity.toggleHideShowKeyboard() {
val inputMethodManager = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
when {
inputMethodManager.isActive -> inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
else -> inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0) // hide
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment