[英]MotionEvent.ACTION_UP on Textview
My TextView does not support the MotionEvent.Action_UP. 我的TextView不支持MotionEvent.Action_UP。 I only get 0 on event.getAction.
我在event.getAction上只得到0。
But the same Code works perfekt for a ImageButton. 但是相同的代码对于ImageButton来说是完美的。
Doesn't a Textview support the MotionEvent.Action_UP? Textview不支持MotionEvent.Action_UP吗?
textView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
Log.v("tag","textView"+event.getAction());
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.v("tag","textViewmousedown");
} else if(event.getAction() == MotionEvent.ACTION_UP) {
//This gets never called
Log.v("tag","textViewmouseup");
if (standardButtonClickListener != null) {
standardButtonClickListener.onStandardButtonClick(v);
}
}
return false;
}
});
You have to return true
instead of false
in your onTouch
method. 您必须在
onTouch
方法中返回true
而不是false
。 This way, further events will be delivered to your listener. 这样,其他事件将传递给您的听众。
Don't forget MotionEvent.ACTION_CANCEL 不要忘记MotionEvent.ACTION_CANCEL
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
setColorFilter(Color.argb(155, 185, 185, 185));
}
else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
setColorFilter(Color.argb(0, 185, 185, 185));
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.