Switch button - disable swipe function

后端 未结 6 594
名媛妹妹
名媛妹妹 2020-12-17 09:42

I have a switch button (actually is a custom one) and I want to disable the swipe functionality for some reason; I want the user to be able to click it only. Is

6条回答
  •  佛祖请我去吃肉
    2020-12-17 10:06

    You can custom a view that extends Switch then override its onTouchEvent()

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean handle = ev.getActionMasked() == MotionEvent.ACTION_MOVE;
        return handle ? handle : super.onTouchEvent(ev);
    }
    

    It should work.

提交回复
热议问题