@SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { if (shouldShowClearButton(length()) && event.action == ACTION_UP && event.endDrawableTouched()) { setText("") return true } return super.onTouchEvent(event) }
Clears the text when the clear icon is touched. Since the icon is just a compound drawable, we check the tap location to see if the X position of the tap is where the drawable is located.