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

后端 未结 8 771
死守一世寂寞
死守一世寂寞 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:26
    //create Dialog by using below method
    
    @Override
    protected Dialog onCreateDialog(int id) {
    
        switch (id) {
    
        case DIALOG1_KEY: {
            Dialog dialog = new Dialog(this,R.style.NewDialog);
            dialog.setContentView(R.layout.progress);
            dialog.setCancelable(true);
            return dialog;
        }
        }
        return null;
    }
    
    //then in your onCreate () you can call like below
    
    @Override
    
    public void onCreate(Bundle savedInstatncestate)
    
    {
    
    final Handler mHandler = new Handler();
    showDialog(DIALOG1_KEY);
    new Thread() {
    public void run() {
    try {
        sleep(3000);
        Runnable r = new Runnable() 
        {
        public void run() 
        {
                   //do your background process
    
                 dismissDialog(DIALOG1_KEY);
        }
    
            };
    mHandler.post(r);
         } catch (Exception e) {
         }
       }
    }.start();
    }
    
    0 讨论(0)
  • 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();
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题