Summary: After a custom view Android rewrite onTouchEvent method, also want to respond to onClick method into effect, it is best to call it performClick () method up in the event.
helpLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
helpLayout.setSelected(true);
helpLayout.setPressed(true);
settingLayout.setSelected(false);
aboutLayout.setSelected(false);
break;
case MotionEvent.ACTION_UP:
helpLayout.setPressed(false);
//添加此方法,使onclick事件生效
helpLayout.performClick();
break;
}
return false;
}
});
For more details, see: https: //www.jianshu.com/p/7d1e773d9955