[英]MotionEvent.ACTION_UP on Textview
我的TextView不支持MotionEvent.Action_UP。 我在event.getAction上只得到0。
但是相同的代码对于ImageButton来说是完美的。
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;
}
});
您必须在onTouch
方法中返回true
而不是false
。 这样,其他事件将传递给您的听众。
不要忘记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.