I have an开发者_如何学运维 onLongClick event on a button but after a long click, the coloured highlight is not removed. I also have an onClick event on the same button which behaves as expected.
Put another way, the button is coloured as you start the click, and the colour should be removed when you release the click. For onClick it works ok, but onLongClick the highlight is not removed.
This is the same whether onLongClick returns true or false.
For anyone else having a similar problem: Not clearing the highlight on a button is often caused by your onLongClick listener consuming the event without canceling the selection. Try something akin to
MotionEvent cancel = MotionEvent.obtain(e2);
cancel.setAction(MotionEvent.ACTION_CANCEL);
view.onTouchEvent(cancel);
cancel.recycle();
and you should see it de-select, as long as you're not also eating the ACTION_CANCEL.
精彩评论