其实道理和圆形进度条对话框差不多,只是方法有些不一样
ProgressDialog(Context context):构造方法
setProgressStyle(int style):设置样式
ProgressDialog.STYLE_HORIZONTALL:水平进度条
//水平进度条
public void showhp(View view) {
final ProgressDialog dialog = new ProgressDialog(this);//构造方法
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//设置样式格式
dialog.show();//显示
new Thread(new Runnable() {//主线程
@Override
public void run() {//分线程
// TODO Auto-generated method stub
int count = 100;//
dialog.setMax(count);//设置最大进度条
for(int i=0;i<count;i++) {
try {
Thread.sleep(100);//休息一会
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dialog.setProgress(dialog.getProgress()+1);//设置当前进度,每执行一次循环体就加一
}
dialog.dismiss();//移除对话框
}
}) .start();
}