您可以使用此处显示的代码简单地创建对话框 (AlertDialog):http: //developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
如果您需要使用不会立即关闭对话框本身的按钮创建对话框,您可以在此处查看我的答案:如何防止单击按钮时关闭对话框