privatevoiddialog1(){
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);//先得到构造器
builder.setTitle("提示");//设置标题
builder.setMessage("是否确认退出?");//设置内容
builder.setIcon(R.mipmap.ic_launcher);//设置图标,图片id即可
builder.setPositiveButton("确定",newDialogInterface.OnClickListener(){//设置确定按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();//关闭dialog
Toast.makeText(MainActivity.this,"确认"+which,Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消",newDialogInterface.OnClickListener(){//设置取消按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
Toast.makeText(MainActivity.this,"取消"+which,Toast.LENGTH_SHORT).show();
}
});
builder.setNeutralButton("忽略",newDialogInterface.OnClickListener(){//设置忽略按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
Toast.makeText(MainActivity.this,"忽略"+which,Toast.LENGTH_SHORT).show();
}
});
//参数都设置完成了,创建并显示出来
builder.create().show();
}