Disable All Touch Screen Interactions While Animation

前端 未结 4 787
醉梦人生
醉梦人生 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:24

    Eventually I took as a basic answer of @Matthieu and make it work such way. I decide to publish my answer because it take me maybe 30 min to understood why I got error.

    XML

    <...your path to this view and in the end --> .TouchBlackHoleView
        android:id="@+id/blackHole"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    Class

    public class TouchBlackHoleView extends View { private boolean touchDisable = false;

    public TouchBlackHoleView(Context context) {
        super(context);
    }
    
    public TouchBlackHoleView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public TouchBlackHoleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return touchDisable;
    }
    
    public void disableTouch(boolean value){
        touchDisable = value;
    }
    }
    

    Using

    blackHole = (TouchBlackHoleView) findViewById(R.id.blackHole);
    blackHole.disableTouch(true);
    

    Enjoy

提交回复
热议问题