通过sleep
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = new ProgressDialog(this);
progress.setMessage("Downloading...");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
progress.show();
final int totalTime = 50;
final Thread t = new Thread() {
@Override
public void run() {
int jumpTime = 0;
while (jumpTime < totalTime) {
try {
sleep(200);
jumpTime += 10;
progress.setProgress(jumpTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
};
t.start();
}