Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Clear focus on touch outside for all EditText inputs.
- */
- override fun dispatchTouchEvent(event: MotionEvent): Boolean {
- 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)
- // hide your button
- }
- }
- }
- return super.dispatchTouchEvent(event)
- }
Advertisement
Add Comment
Please, Sign In to add comment