I have EditText
and icon inside it
<EditText
android:id="@+id/myedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@mipmap/microphone"/>
I Set onClickListener
for the Drawable
right of an EditText
myeditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() >= (myeditText.getRight() - myeditText
.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
// your action here
Toast.makeText(getApplicationContext(),
"speak",Toast.LENGTH_SHORT).show();
return true;
}
}
return false;
}
});
when I click to icon right of EditText
Toast show me and work, but show me paste option on EditText
too.
how can I remove paste when icon in right clicked?
In my case changing from
ACTION_UP
toACTION_DOWN
gave effect. Of course, behaviour sligtly changed. And cursor still jumps to the end of a text.You can take a look at this question and see how to disable the paste.
But I'd suggest something else, instead of disabling paste, you can probably do this in a different way. Looking at whatsapp's microphone button +
EditText
placement, I notice that they're two different elements, and this is what you may do. Wrap yourEditText
in a horizontalLinearLayout
and place a button with a microphone at the right end. I hope you can manage to make it work, and that you understand my idea.Just set android:longClickable="false" to editbox.