一般有两种对话框,一个是普通的简单的please wait对话框,另一种是创建显示操作进度(如下载状态)的对话框。
第一种普通的效果图如下:
第一种普通的实现代码:
public void onClick2(View v){ final ProgressDialog progressDialog =ProgressDialog.show(this, "progressbar", "please waiting..."); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { Thread.sleep(3000); progressDialog.dismiss(); } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } } }).start(); }
第二种效果图如下:
第二种实现代码如下:
ProgressDialog progressDlg; public void onClick2(View v){ showDialog(1); progressDlg.setProgress(0); Thread thread = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { for(int i = 0; i< 20;i++){ Thread.sleep(500); progressDlg.incrementProgressBy(100/20); } } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } progressDlg.dismiss(); } }); thread.start(); return; }