Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun Activity.hideKeyboard(event: MotionEvent) {
- if (event.action == MotionEvent.ACTION_DOWN) {
- val v = currentFocus
- if (v is EditText) {
- val outRect = Rect()
- v.getGlobalVisibleRect(outRect)
- if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
- v.clearFocus()
- val imm: InputMethodManager =
- getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
- imm.hideSoftInputFromWindow(v.getWindowToken(), 0)
- }
- }
- }
- }
- override fun dispatchTouchEvent(event: MotionEvent): Boolean {
- hideKeyboard(event)
- return super.dispatchTouchEvent(event)
- }
Advertisement
Add Comment
Please, Sign In to add comment