Skip to content

Instantly share code, notes, and snippets.

@smkazemi
Last active March 9, 2020 16:36
Show Gist options
  • Save smkazemi/0344bac64d3d9f1cdf5a580d4ef55577 to your computer and use it in GitHub Desktop.
Save smkazemi/0344bac64d3d9f1cdf5a580d4ef55577 to your computer and use it in GitHub Desktop.
Hide & show android keyboard
// keyboard hide after click on button
val inputMethodManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
// when click on button hideKeyboard() call
btn_done.setOnClickListener {
showKeyboard(it)
hideKeyboard(it)
}
// @params v is that button clicked on it
private fun hideKeyboard(v: View?) {
inputMethodManager.hideSoftInputFromWindow(v?.windowToken, 0)
}
// @params v is that button clicked on it
private fun showKeyboard(v: View) = inputMethodManager.showSoftInput(v, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment