圆圈的进度条式 窗口直接用show,水平进度必须创建类并创建构造方法
圆圈的进度条式 的Dialog(窗口)
public void showPD(View view) throws InterruptedException {
final ProgressDialog dialog = ProgressDialog.show(this,"数据加载","数据加载中...");
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0;i<20;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
dialog.dismiss();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(DialogActivity.this,"加载完成",Toast.LENGTH_SHORT).show();
}
});
}
}).start();
}
水平的进度条式 的Dialog(窗口)
public void showPD2(View view)
{
final ProgressDialog pd = new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.show();
new Thread(new Runnable() {
@Override
public void run() {
pd.setMax(20);
for(int i =0;i<20;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
pd.setProgress(pd.getProgress()+1);
}
pd.dismiss();
}
}).start();
}
一个show(ProgressDialog.show) 一个new (new ProgressDialog(this))