Skip to content

Instantly share code, notes, and snippets.

@MartuPuri
Created October 12, 2017 20:13
Show Gist options
  • Save MartuPuri/9acd0ac8b0479601c4e9fcf13cb2d623 to your computer and use it in GitHub Desktop.
Save MartuPuri/9acd0ac8b0479601c4e9fcf13cb2d623 to your computer and use it in GitHub Desktop.
Kotlin Extension - View
fun View.showKeyboard(context: Context) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(this, InputMethodManager.SHOW_FORCED)
}
fun View.hideKeyboard(context: Context) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(this.windowToken, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment