Disable All Touch Screen Interactions While Animation

前端 未结 4 770
醉梦人生
醉梦人生 2020-12-29 07:55

I wish to disable all the touch screen interactions while an animation is being displayed. I don\'t wish to use the setClickable() method on the buttons at the

4条回答
  •  被撕碎了的回忆
    2020-12-29 08:36

    In your Activity, you can override onTouchEvent and always return true; to indicate you are handling the touch events.

    You can find the documentation for that function there.

    Edit Here is one way you can disable touch over the whole screen instead of handling every view one by one... First change your current layout like this:

    
    
        < .... put your current layout here ... />
    
        
    
    

    And then define your custom view with something like this:

    public class TouchBlackHoleView extends View {
        private boolean touch_disabled=true;
        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return touch_disabled;
        }
        public disable_touch(boolean b) {
            touch_disabled=b;
        }
    }
    

    Then, in the activity, you can disable the touch with

    (TouchBlackHoleView) black_hole = findViewById(R.id.black_hole);
    black_hole.disable_touch(true);
    

    And enable it back with

    black_hole.disable_touch(false);
    

提交回复
热议问题