普通对话框
public void puTong(View v) {
Builder builder = new AlertDialog.Builder(this);
// 设置主题
builder.setTitle("通知");
// 设置消息
builder.setMessage("5.1放假三天,外出的朋友们注意天气");
// 确认的按钮
builder.setPositiveButton("确认", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "点击确定了......", 0).show();
}
});
// 取消的按钮
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "点击取消了", 0).show();
}
});
builder.show();
}
单选对话框
public void danXuan(View v) {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请选择您的性别");
final String[] items = { "female", "male" };
builder.setSingleChoiceItems(items, -1, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "你的选择是:" + items[which] + ",脚标是:" + which, 0).show();
}
});
builder.show();
}
多选对话框
public void duoXuan(View v) {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle("每天做的事");
final String[] items = { "上课", "敲代码", "睡觉", "玩手机", "听音乐", "下课" };
boolean[] checkedItems = { true, false, true, false, false, true };
builder.setMultiChoiceItems(items, checkedItems, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Toast.makeText(getApplicationContext(), "你的选择是:" + items[which] + ",脚标是:" + which + "状态是:" + isChecked,
0).show();
}
});
builder.show();
}
进度对话框--只转圈
public void zhuanQuan(View v) {
final ProgressDialog dialog = ProgressDialog.show(this, "下载", "亲,您的电影正在加载中");
new Thread() {
public void run() {
SystemClock.sleep(2000);
// Toast.makeText(getApplicationContext(), "下载已完成",0).show();
dialog.dismiss();
System.out.println("下载已完成");
};
}.start();
}
进度对话框--进度条
public void jinDu(View v) {
final ProgressDialog dialog = new ProgressDialog(this);
// 设置主题
dialog.setTitle("下载的进度");
// 设置类型
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 设置最大进度
dialog.setMax(100);
new Thread() {
public void run() {
for (int i = 0; i < 100; i++) {
SystemClock.sleep(200);
dialog.setProgress(i);
}
// 当循环完后让对话框消失
dialog.dismiss();
};
}.start();
// Toast.makeText(this, "下载已完成",0).show();
System.out.println("下载已完成......");
dialog.show();
}