timed modeless dialog

前端 未结 3 1434
礼貌的吻别
礼貌的吻别 2020-12-05 01:06

Is there any way to show a modeless dialog--a dialog that allows the user to interact with whatever was on the screen before the dialog but also allows the user to interact

3条回答
  •  死守一世寂寞
    2020-12-05 02:04

    Yes, create an Activity with style Theme.Dialog. This is a normal activity which looks like a dialog, while being modeless and accepting events.

    An example:

    
    

    Edited:

    Indeed Theme.Dialog blurs the underlying activity and makes it unaccessible. I had a similar requirement here I had to show upload progress dialog with text and cancel button. The main catch is in setting WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL and resetting WindowManager.LayoutParams.FLAG_DIM_BEHIND.

    Created a Dialog with custom content:

        if (progressDialog == null) {
                progressDialog = new Dialog(activityRequestingProgressDialog);
                progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                progressDialog.setContentView(R.layout.progress_upload);
                progressBar = (ProgressBar) progressDialog.findViewById(R.id.progressBar);
                progressText = (TextView) progressDialog.findViewById(R.id.progressText);
                progressText.setText("0 %");
                progressText.setTextSize(18);
                Button buttonCancel = (Button) progressDialog.findViewById(R.id.btnCancel);
                buttonCancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                        cancelProgressDialog();
                        stopUpload("Upload cancelled.");
                    }
                });
                Window window = progressDialog.getWindow();
                window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
                window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                window.setGravity(Gravity.BOTTOM);
                progressDialog.show();
            }
    
            progressText.setText(text);
            progressBar.setProgress(percent);
    

    And this is the layout for this Dialog:

    
    
    
    
    
    
        
    
        
    
        

提交回复
热议问题