Skip to content

Instantly share code, notes, and snippets.

@Tamkien
Last active October 14, 2020 08:00
Show Gist options
  • Save Tamkien/46e46b66f7b222f82d5b0a9fc4b58526 to your computer and use it in GitHub Desktop.
Save Tamkien/46e46b66f7b222f82d5b0a9fc4b58526 to your computer and use it in GitHub Desktop.
Kotlin code for creating OnTouchListener on a DrawableEnd
editTextNumber.setOnTouchListener(object : View.OnTouchListener{//editTextNumber is the id of my EditText that contains the drawable
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_UP){
if (event.rawX >= editTextNumber.right - editTextNumber.compoundDrawables[2].bounds.width()){ //*Why [2]? See below
Log.d("DrawableEnd", "Pressed")//Insert your action here
return true
}
}
return false
}
})
/* DRAWABLE_LEFT = 0
DRAWABLE_TOP = 1
DRAWABLE_RIGHT = 2
DRAWABLE_BOTTOM = 3*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment