Disable the touch events for all the views

前端 未结 13 1383
暗喜
暗喜 2020-11-28 06:53

What\'s the best way to disable the touch events for all the views?

13条回答
  •  温柔的废话
    2020-11-28 07:14

    I made this method, which works perfect for me. It disables all touch events for selected view.

    public static void disableView(View v) {
    
        v.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                disableView(child);
            }
        }
    }
    

提交回复
热议问题