you could override the Button
's onTouchListener
, and return immediately it the touch event is not performed through TOOL_TYPE_STYLUS
. To retrieve this information, you can use
getToolType(int pointerX)
From the documentation
Gets the tool type of a pointer for the given pointer index
if it returns TOOL_TYPE_STYLUS
, then you can simply check the MotionEvent
for the ACTION_DOWN
/ACTION_UP
, and call performClick()
. E.g.
b.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS) {
if (event.getAction() == MotionEvent.ACTION_UP ) {
performClick();
return true;
}
}
return false;
}
});