How to center progress indicator in ProgressDialog easily (when no title/text passed along)

后端 未结 8 847
死守一世寂寞
死守一世寂寞 2020-11-28 00:43

When calling progressDialog = ProgressDialog.show(this, null, null, true); usually the developers wants to only show the progress indication image, and usually

8条回答
  •  無奈伤痛
    2020-11-28 01:27

    I use the following, it requires no layout file, and puts a centered, borderless blocking progress bar in the middle of the screen.

    private ProgressDialog progressDialog;
    
    
    setUIToWait(true);
    
    ...long process...
    
    setUIToWait(false);
    
    
    private void setUIToWait(boolean wait) {
    
        if (wait) {
            progressDialog=ProgressDialog.show(this,null,null);
            progressDialog.setContentView(new ProgressBar(this));
        } else {
            progressDialog.dismiss();
        }
    
    }
    

提交回复
热议问题