检测用户何时离开 Android 中的按钮
是否有可能检测到用户按下按钮后将手指从按钮上移开的任何时间?
我已经确定,当用户垂直离开按钮时,onTouchListener 将获得一个操作(它给出一个操作:ACTION_CANCEL),但我无法找到一种方法来确定用户何时水平离开按钮。
public boolean onTouch(View arg0, MotionEvent arg1) {
switch(arg1.getAction()){
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.untouched);
break;
}
break;
case MotionEvent.ACTION_DOWN:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.touched);
break;
}
break;
}
return false;
}
Is it possible to detect anytime a user moves their finger off of a button after they have been pressing down on it?
I have determined that onTouchListener will get an action when the user moves off of the button vertically (It gives an action: ACTION_CANCEL), but I have not been able to find a way to determine when a user moves off the button horizontally.
public boolean onTouch(View arg0, MotionEvent arg1) {
switch(arg1.getAction()){
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.untouched);
break;
}
break;
case MotionEvent.ACTION_DOWN:
switch(arg0.getId()){
case R.id.my_button:
button.setBackgroundResource(R.drawable.touched);
break;
}
break;
}
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试下一步:
arg1 - 来自您的代码
在这里您可以获得 MotionEvent 的坐标。接下来你将用这个坐标做任何事情
希望它对你有帮助
Try go next:
arg1 - is from your code
Here you can get coordinates of MotionEvent. Next you will do anything with this coordinates
Hope, it help you