你可以用一个AlertDialog,并使用它构造一个Builder班级,等级。下面的示例使用默认构造函数,该构造函数只接受Context因为对话框将从传入的上下文继承适当的主题,但是也有一个构造函数,允许您指定特定的主题资源作为第二个参数(如果您想这样做的话)。new AlertDialog.Builder(context)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Continue with delete operation
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.setIcon(android.R.drawable.ic_dialog_alert)
.show();