设置Handler
Handler signHandler = new Handler() {
publicvoid handleMessage(Message msg) {
switch(msg.what) {
case 1: //当msg.what==1时执行
Log.i("执行","执行");
}
signHandler.sendEmptyMessage(1);//设置msg.what
}
// 创建ProgressDialog对象 |
015 | ProgressDialog progressdialog; |
可直接progressdialog = ProgressDialog.show(getContext(), null, "正在登录...");
progressdialog.setOnKeyListener(new DialogInterface.OnKeyListener(){
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {//监听返回键
dialog.dismiss();
return true;
}
return false;
}
});
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {//监听返回键
dialog.dismiss();
return true;
}
return false;
}
});
或:
033 | //创建ProgressDialog对象 |
034 | progressdialog = new ProgressDialog(Android2Activity. this ); |
035 |
036 | // 设置进度条风格,风格为圆形,旋转的( ProgressDialog.STYLE_HORIZONTAL长形风格) |
037 | progressdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
038 |
039 | // 设置ProgressDialog 标题 |
040 | progressdialog.setTitle( "提示" ); |
041 | |
042 | // 设置ProgressDialog 提示信息 |
043 | progressdialog.setMessage( "正在缓冲中,请稍等....." ); |
044 |
045 | // 设置ProgressDialog 标题图标 |
046 | // m_pDialog.setIcon(R.drawable.img1); |
047 |
048 | // 设置ProgressDialog 的进度条是否不明确 |
049 | progressdialog.setIndeterminate( false ); |
050 | |
051 | // 设置ProgressDialog 是否可以按退回按键取消 |
052 | progressdialog.setCancelable( true ); |
053 | |
054 | // 设置ProgressDialog 的一个Button |
055 | progressdialog.setButton( "确定" , new DialogInterface.OnClickListener() { |
056 | public void onClick(DialogInterface dialog, int i) |
057 | { |
058 | //点击“确定按钮”取消对话框 |
059 | dialog.cancel(); |
060 | } |
061 | }); |
062 |
063 | // 让ProgressDialog显示 |
064 | progressdialog.show(); |