安卓已过时的ProgressDialog对话框

private ProgressDialog mDialog;
private Handler mHandler;  //初始化Handler


//初始化
mDialog = new ProgressDialog(CeYaActivity.this); //可以放在Oncreat里面

mHandler = new Handler() {                //放入Oncreate里面
@Override
public void handleMessage(Message msg) {

if(msg.what == 0 ){

mDialog.setProgress(msg.arg1);
}else if (msg.what == 1){

post(mCloseDialog);
}



}
};


//关闭弹出页面
private Runnable mCloseDialog = new Runnable() {
@Override
public void run() {
if(mDialog.isShowing()){
mDialog.dismiss();

}
}
};

//进度条子线程
Runnable testTast = new Runnable() {

@Override
public void run() {

for (int i = 0 ; i < 10 ; i ++){
Message message = Message.obtain(); //获取一个默认的消息对象
message.what = 0 ;
message.arg1 = i * 10;
mHandler.sendMessage(message);

try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}


}
mHandler.sendEmptyMessage(1);

}
};

//调用的方法
private  void  test(){

mDialog.setTitle("上传数据");
mDialog.setMessage("正在努力上传数据");
mDialog.setMax(100);
mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mDialog.show();

new Thread(testTast).start();

}






安卓已过时的ProgressDialog对话框

上一篇:华为手机usb调试打开后自动关闭怎么办?华为手机 usb调试为什么自动关闭?usb调试老是自动关闭怎么回事?


下一篇:app逆向入门分析——APP登陆请求参数