I have implemented Custom EditText where I want to get all CompoundDrawables click. I have got success to get Right and Left drawable click.
I have also get partial success to get the Top drawable click.
Here is my EditText Image:
What I got: I got success to get the Click Event (TouchEvent) for Top area covered by RED rectangle. Here is the code for the same.
Code:
override fun onTouchEvent(event: MotionEvent): Boolean {
var bounds: Rect?
if (event.action == MotionEvent.ACTION_DOWN) {
positionX = event.x.toInt()
positionY = event.y.toInt()
if (drawableTop != null) {
bounds = drawableTop!!.bounds
val xClickPosition: Int = positionX
val yClickPosition: Int = positionY
val extraClickingArea = 13
if (xClickPosition >= (paddingLeft - extraClickingArea)) {
if (xClickPosition <= (width - paddingRight + extraClickingArea)) {
if (yClickPosition >= (paddingTop - extraClickingArea)) {
if (yClickPosition <= (paddingTop + bounds.height() + extraClickingArea)) {
//I have to get Only Top drawable Bound here
onDrawableClickListener!!.onClick(DrawablePosition.TOP)
event.action = MotionEvent.ACTION_CANCEL
return false
}
}
}
}
}
}
return super.onTouchEvent(event)
}
What I want:
But I only want click event covered by GREEN rectangle.
EditText Image:
How can I achieve this?

