Last active
March 9, 2020 16:36
-
-
Save smkazemi/0344bac64d3d9f1cdf5a580d4ef55577 to your computer and use it in GitHub Desktop.
Hide & show android keyboard
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
// 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