有两个子类
一、CharacterPickerDialog
二、 AlertDialog 一般警示对话框
DatePickerDialog 日期对话框
Progress Dialog 进度条对话框
Time PickerDialog 时间对话框
.show();//弹出对话框
.dismiss();//对话框消失
AlertDialog :
不能直接new,需要中间AlertDialog.Builder
AlertDialog .Builder builder= new AlertDialog.Builder(Context context);
AlertDialog alertDialog = builder.create();//创建AlertDialog 对话框
//它里面的内容需要全部用builder来设置
监听时需声明是View 还是DialogInterface下的onClickListener
builder.setTilte("title"); //设置标题
builder.setMessage("content"); //设置内容
builder.setIcon(int id); //设置标题图片头像
//三个按钮,位置是系统自己定了的
//注意他的监听 onclickListener 是DialogInterface接口的,不是View
builder.setNagativeButton("btnName",new DialogInterface.onclickListener(){}); //取消, 位置在左边 -2
builder.setPositiveButton(); //确认 右边 -1
builder.setNeutralButton();//继续 中间 -3 ---监听是的int which值
//可以设置单项选择对话框以及多选
//注意设置这个就不能再设置Message了,会将其覆盖
builder.setSingleChoiceItems(new String[opt1,opt2],int position,new DialogInterface.OnclickListener()...);//int position 是默认第几个选项被选中
buidler.setMultiChoiceItems(new String[]{"opt1","opt2","opt3"},new boolean[]{false,true,false},.....)// false:不选中,true 选中,每个选项都要设置
AlertDialog.Builder builder = new AlertDialog.Builder(this); //new AlertDialog.Builer builder.setTitle("pls select your sex"); builder.setSingleChoiceItems(new String[] { "man", "woman" }, 1, new <span style="color:#ff0000;">DialogInterface.OnClickListener</span>() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogActivity.this, which + " " + dialog.toString(), Toast.LENGTH_SHORT).show(); } }); builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogActivity.this, " " + which, Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogActivity.this, "" + which, Toast.LENGTH_SHORT).show(); } }); builder.create().show(); //顯示
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("pls select below information"); builder.setMultiChoiceItems( new String[] { "socer", "footbal", "clim" }, new boolean[] { false, false, false }, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { Toast.makeText(DialogActivity.this, which + " " + dialog.toString(), Toast.LENGTH_SHORT).show(); } }); builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogActivity.this, " " + which, Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogActivity.this, "" + which, Toast.LENGTH_SHORT).show(); } }); builder.create().show();