AlertDialog是一个带有确定取消按钮的系统弹窗,因为是系统控件,不需要在layout.xml中注册,直接使用代码即可.
void showAlert(){
AlertDialog.Builder dialog = new AlertDialog.Builder(SubActivity.this);
dialog.setTitle("This is Dialog");
dialog.setMessage("Something important.");
dialog.setCancelable(false);
dialog.setPositiveButton("好", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//点击确定,窗口会自动关闭
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//点击取消,窗口会自动关闭
}
});
dialog.show();
}
解释
setPositiveButton(确定)和setNegativeButton(取消)分别设置点击之后的动作. ProgressDialog示例ProgressDialog和AlertDialog非常类似,它没有两个按钮,只有一个loading动画.
void showProgress(){
ProgressDialog progressDialog = new ProgressDialog(SubActivity.this);
progressDialog.setTitle("This Title");
progressDialog.setMessage("Plese wait");
progressDialog.setCancelable(true);
progressDialog.show();
}
setCancelable() 解释
这两个控件都有setCancelable()方法; |

黑色衣服鞋子外贸商城|
人气:755
家居用品商城系统|ecshop家
人气:898
仿乐蜂网化妆品商城模板
人气:736
ecshop也买茶模板|ecshop茶叶
人气:979
shopex仿好乐买模板
人气:749
图书音像商城整站源码|
人气:1105