Guest User

Untitled

a guest
Nov 3rd, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /**
  2. * Clear focus on touch outside for all EditText inputs.
  3. */
  4. override fun dispatchTouchEvent(event: MotionEvent): Boolean {
  5. if (event.action == MotionEvent.ACTION_DOWN) {
  6. val v = currentFocus
  7. if (v is EditText) {
  8. val outRect = Rect()
  9. v.getGlobalVisibleRect(outRect)
  10. if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
  11. v.clearFocus()
  12. val imm: InputMethodManager =
  13. getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
  14. imm.hideSoftInputFromWindow(v.getWindowToken(), 0)
  15. // hide your button
  16. }
  17. }
  18. }
  19. return super.dispatchTouchEvent(event)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment