---
title: "进度条大全"
author: "AndLi"
date: "2011-10-11T07:11:13Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2011-10-11T07:11:13Z"
id: 1189194
url: "https://andli.iteye.com/blog/1189194"
---

1.对话框进度条

![](http://dl.iteye.com/upload/attachment/567567/72e053a5-5213-37ac-8d7e-f7bb7869f39a.png)

 

```
public class MainActivity extends Activity {
	private Button myBtn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myBtn = (Button)findViewById(R.id.Button01);
        myBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				showDialog(0);
			}
		});
    }

	@Override
	protected Dialog onCreateDialog(int id) {
		ProgressDialog dialog = new ProgressDialog(this);
		// 可以不显示标题
		dialog.setTitle("测试对话框");
		dialog.setIndeterminate(true);
		dialog.setMessage("程序正在加载请稍后！");
		dialog.setCancelable(true);
		
		dialog.setButton(Dialog.BUTTON_POSITIVE, "确定", 
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				}
		);
		return dialog;
	}
}
```

   
 2.标题栏进度条

![](http://dl.iteye.com/upload/attachment/567574/c7bb1f9d-0863-3520-8e1e-b9e139fd84d8.png)  
 

 

```
public class MainActivity extends Activity {
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
```

```
 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
```

```
       setContentView(R.layout.main);
       b1 = (Button)findViewById(R.id.Button01);
       b2 = (Button)findViewById(R.id.Button02);
       
       b1.setOnClickListener(new OnClickListener() {
		public void onClick(View v) {
```

```
setProgressBarIndeterminateVisibility(true);	
```

```
}
       });
       
       b2.setOnClickListener(new OnClickListener() {
   		public void onClick(View v) {
   			
```

```
setProgressBarIndeterminateVisibility(false);
```

```
}
       });
    }
}
```

 3.水平进度条

![](http://dl.iteye.com/upload/attachment/567576/d3387351-cae2-30fa-b3d3-827455d828b1.png)  
 

```
progressBar = (ProgressBar)findViewById(R.id.ProgressBar01);
        
        b1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
					
```

```
progressBar.incrementProgressBy(1);
```

```
			}
		});
        
        b2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
```

```
progressBar.incrementProgressBy(-1);
```

```
			}
		});
```