Open Logerfo opened 8 years ago
ive noticed the same thing. same issue described and same behavior with the swipe described. i can get it to work if i set the app:additionalTouchTargetSize
sufficiently large (like 100dp
), but im hesitant to do that because it seems hacky.
i think something like this should fix it -- i think the problem stems from using getLeft()
and getRight()
@Override
public boolean onTouchEvent(MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_UP && mVisibilityDrawable != null ) {
Rect bounds = mVisibilityDrawable.getBounds();
float clickX = event.getX();
float iconXStart = mIsRightToLeft ? getWidth() - getTotalPaddingLeft() : getWidth() - getTotalPaddingRight();
//check if the touch is within bounds of mVisibilityDrawable icon
if ( iconXStart <= clickX && clickX < iconXStart + bounds.width() ) {
togglePasswordVisibility();
//use this to prevent the keyboard from coming up
event.setAction(MotionEvent.ACTION_CANCEL);
}
}
return super.onTouchEvent(event);
}
@joshkendrick I don't understand how this would explain the swipe behavior
my issue was that the icon wouldnt work at all if my layout was android:layout_centerHorizontal=true
-- that's what the above seems to have fixed for me.
swipe doesnt seem to be fixed, but im betting the swipe behavior is due to to this being checked on MotionEvent.ACTION_UP
, (and not entirely related to any centerHorizontal
stuff)
I see. So this is probably two (semi) separated issues. I cannot test it at the moment, but I guess the perfect pull request for that would get rid of both issues, since they are probably in the same piece of code. Does swiping actually trigger MotionEvent.ACTION_UP
?
I've noticed the icon would not work if I set
android:layout_centerHorizontal=true
in theShowHidePasswordEditText
view, but I also observed that it would work (and apparently that's only way) if I swipe the icon from left to right.PS: I'm using RelativeLayout, I don't know if this makes any difference.
Edit: I forgot to mention that I'm also using api 24.