Disable a whole activity from user action

后端 未结 7 669
再見小時候
再見小時候 2020-12-02 09:17

Is there a simple way to disable a user interacting with an activity. To be done when there is an action running (and a spinning progress bar in the title bar)

EDIT:

7条回答
  •  半阙折子戏
    2020-12-02 09:37

    I solved this by adding an full screen blank image with a null click handler at the end on the XML layout.

    Create a transparent PNG file in the drawables folder.

    Add a full screen ImageView at the end of the XML layout referencing the image:

    ...
     
    

    Add the null click hander for the image to capture user touches:

    public void doNothingClick(View v){
        // do nothing with the click
    }
    

    Add the code to disable the user touches:

    private void StopTouches(int duration){
        findViewById(R.id.imgMask).setVisibility(View.VISIBLE);
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                findViewById(R.id.imgMask).setVisibility(View.GONE);
            }
        }, duration);
    }
    

提交回复
热议问题