四:ProgressDialog

ProgressDialog,进度对话框 函数有以下:

          setIndeterminate(boolean indeterminate),设置对话框里的进度条不显示进度值

          setMax(int max),设置对话框里进度条的最大值

          setMessage(CharSequence message),设置对话框里要显示的内容

          setProgress(int value),设置对话框里进度条的进度值

          setProgressStyle(int style),设置对话框里进度条的风格
          incrementProgressBy (int diff) ,增加和减少进度
          进度条弹出框不需要调用create创建 直接调用show方法显示即可


使用方法很简单

Activity中代码:例子 用两个button来启动ProgressDialog 
private Button b_dialog,b_dialog1,button;//两个按钮 
    private ProgressDialog pd,pd1;//进度条对话框 
    private int count; 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main);//关联对应的界面 
         b_dialog = (Button)this.findViewById(R.id.dialog);     
         b_dialog1 = (Button)this.findViewById(R.id.dialog1);     
        //处理事件发生时要做的事 
         b_dialog.setOnClickListener(listener); 
         b_dialog1.setOnClickListener(listener);        
    } 
    //定义监听器对象 
    private OnClickListener listener = new OnClickListener() { 
        // 鼠标按下后 
        public void onClick(View v) { 
          // 得到当前被触发的事件的ID —— 类型是int 
          int id = v.getId(); 
          if(id == R.id.dialog){ 

            
            pd = ProgressDialog.show(MainActivity.this, "自动关闭对话框", "Working,,,,,,1秒", true, false);
            pd.show();
//            Thread thread = new Thread(MainActivity.this);//开启一个线程来延时              
//                thread.start();//启动线程 
            new Thread() {      
                public void run() {    
                   try {    
                      while(count <= 50) {    
                      // 由线程来控制进度    
                        
                       if(count==80){
                            Thread.sleep(200);
                       }
                       Thread.sleep(100);
                       count++;
                    }    
                        pd.cancel();    
                    } catch (Exception e) {    
                        pd.cancel();    
                    }    
                 }    
             }.start(); 
            }else if(id == R.id.dialog1){ 
                pd1 = new ProgressDialog(MainActivity.this);// 创建ProgressDialog对象    
                pd1.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 设置进度条风格,风格为水平的          
                pd1.setTitle("提示");// 设置ProgressDialog 标题    
                pd1.setMessage("Loading...  呵呵");// 设置ProgressDialog提示信息        
                pd1.setIcon(R.drawable.a_2);// 设置ProgressDialog标题图标        
                // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确    
                pd1.setIndeterminate(false);                  
                pd1.setCancelable(true); // 设置ProgressDialog 是否可以按退回键取消             
                pd1.setProgress(100);// 设置ProgressDialog 进度条进度     
                pd1.show(); // 让ProgressDialog显示   
                count = 0;                                  
                new Thread() {      
                         public void run() {    
                            try {    
                               while(count <= 100) {    
                               // 由线程来控制进度    
                                pd1.setProgress(count++);
                                if(count==80){
                                    
                                     Thread.sleep(500);
                                }
                                Thread.sleep(100);    
                             }    
                                 pd1.cancel();    
                             } catch (Exception e) {    
                                 pd1.cancel();    
                             }    
                          }    
                      }.start();    
    } 
        } 
    };