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();
AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(AlertDialogActivity.this);
// Setting Dialog TitlealertDialog2.setTitle("Confirm Delete...");
// Setting Dialog MessagealertDialog2.setMessage("Are you sure you want delete this file?");
// Setting Icon to DialogalertDialog2.setIcon(R.drawable.delete);
// Setting Positive "Yes" BtnalertDialog2.setPositiveButton("YES",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// Write your code here to execute after dialogToast.makeText(getApplicationContext(),"You clicked on YES", Toast.LENGTH_SHORT).show();}});
// Setting Negative "NO" BtnalertDialog2.setNegativeButton("NO",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// Write your code here to execute after dialogToast.makeText(getApplicationContext(),"You clicked on NO", Toast.LENGTH_SHORT).show();dialog.cancel();}});
// Showing Alert DialogalertDialog2.show();
SingleButtton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {// Creating alert Dialog with one Button
AlertDialog alertDialog = new AlertDialog.Builder(AlertDialogActivity.this).create();
// Setting Dialog TitlealertDialog.setTitle("Alert Dialog");
// Setting Dialog MessagealertDialog.setMessage("Welcome to Android Application");
// Setting Icon to DialogalertDialog.setIcon(R.drawable.tick);
// Setting OK ButtonalertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which){// Write your code here to execute after dialog closedToast.makeText(getApplicationContext(),"You clicked on OK", Toast.LENGTH_SHORT).show();}});
// Showing Alert MessagealertDialog.show();}});
btnAlertTwoBtns.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {// Creating alert Dialog with two Buttons
AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
// Setting Dialog TitlealertDialog.setTitle("Confirm Delete...");
// Setting Dialog MessagealertDialog.setMessage("Are you sure you want delete this?");
// Setting Icon to DialogalertDialog.setIcon(R.drawable.delete);
// Setting Positive "Yes" ButtonalertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int which) {// Write your code here to execute after dialogToast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();}});
// Setting Negative "NO" ButtonalertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// Write your code here to execute after dialogToast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();dialog.cancel();}});
// Showing Alert MessagealertDialog.show();}});
btnAlertThreeBtns.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {// Creating alert Dialog with three Buttons
AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
// Setting Dialog TitlealertDialog.setTitle("Save File...");
// Setting Dialog MessagealertDialog.setMessage("Do you want to save this file?");
// Setting Icon to DialogalertDialog.setIcon(R.drawable.save);
// Setting Positive Yes ButtonalertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {// User pressed Cancel button. Write Logic HereToast.makeText(getApplicationContext(),"You clicked on YES",Toast.LENGTH_SHORT).show();}});
// Setting Negative No Button... Neutral means in between yes and cancel buttonalertDialog.setNeutralButton("NO",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {// User pressed No button. Write Logic HereToast.makeText(getApplicationContext(),"You clicked on NO", Toast.LENGTH_SHORT).show();}});
// Setting Positive "Cancel" ButtonalertDialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {// User pressed Cancel button. Write Logic HereToast.makeText(getApplicationContext(),"You clicked on Cancel",Toast.LENGTH_SHORT).show();}});// Showing Alert MessagealertDialog.show();}});
private void showDialog(){String text2 = "<font color=#212121>Medi Notification</font>";//for custom title color
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);builder.setTitle(Html.fromHtml(text2));
String text3 = "<font color=#A4A4A4>You can complete your profile now or start using the app and come back later</font>";//for custom messagebuilder.setMessage(Html.fromHtml(text3));
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which){toast = Toast.makeText(getApplicationContext(), "DELETE", Toast.LENGTH_SHORT);toast.setGravity(Gravity.CENTER, 0, 0);toast.show();}});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which){toast = Toast.makeText(getApplicationContext(), "CANCEL", Toast.LENGTH_SHORT);toast.setGravity(Gravity.CENTER, 0, 0);toast.show();}});builder.show();}
public void showSimpleDialog(View view) {// Use the Builder class for convenient dialog constructionAlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setCancelable(false);builder.setTitle("AlertDialog Title");builder.setMessage("Simple Dialog Message");builder.setPositiveButton("OK!!!", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int id) {//}}).setNegativeButton("Cancel ", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {
}});
// Create the AlertDialog object and return itbuilder.create().show();}
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);dialog.setCancelable(false);dialog.setTitle("Dialog on Android");dialog.setMessage("Are you sure you want to delete this entry?" );dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int id) {//Action for "Delete".}}).setNegativeButton("Cancel ", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//Action for "Cancel".}});
final AlertDialog alert = dialog.create();alert.show();
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);dialog.setCancelable(false);dialog.setTitle("Dialog on Android");dialog.setMessage("Are you sure you want to delete this entry?" );dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int id) {//Action for "Delete".}}).setNegativeButton("Cancel ", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//Action for "Cancel".}});
final AlertDialog alert = dialog.create();alert.show();
new AlertDialog.Builder(this).setTitle("Closing application").setMessage("Are you sure you want to exit?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {
}}).setNegativeButton("No", null).show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setMessage("Are you sure you want to delete this entry?");
builder.setPositiveButton("Yes, please", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//perform any actionToast.makeText(getApplicationContext(), "Yes clicked", Toast.LENGTH_SHORT).show();}});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//perform any actionToast.makeText(getApplicationContext(), "No clicked", Toast.LENGTH_SHORT).show();}});
//creating alert dialogAlertDialog alertDialog = builder.create();alertDialog.show();
AlertDialog alertDialog = new AlertDialog.Builder(this)//set icon.setIcon(android.R.drawable.ic_dialog_alert)//set title.setTitle("Are you sure to Exit")//set message.setMessage("Exiting will call finish() method")//set positive button.setPositiveButton("Yes", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {//set what would happen when positive button is clickedfinish();}})//set negative button.setNegativeButton("No", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {//set what should happen when negative button is clickedToast.makeText(getApplicationContext(),"Nothing Happened",Toast.LENGTH_LONG).show();}}).show();
/*--dialog for delete entry--*/private void cancelBookingAlert() {AlertDialog dialog;final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this, R.style.AlertDialogCustom);alertDialog.setTitle("Delete Entry");alertDialog.setMessage("Are you sure you want to delete this entry?");alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {//code to delete entry}});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {dialog.dismiss();}});
dialog = alertDialog.create();dialog.show();}
val builder: AlertDialog.Builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert)} else {AlertDialog.Builder(this)}builder.setTitle("Delete Alert!").setMessage("Are you want to delete this entry?").setPositiveButton("YES") { dialog, which ->
}.setNegativeButton("NO") { dialog, which ->
}.setIcon(R.drawable.ic_launcher_foreground).show()
var alertDialog = new AlertDialog.Builder(this) // this: Activity.SetTitle("Hello!").SetMessage("Are you sure?").SetPositiveButton("Ok", (sender, e) => { /* ok things */ }).SetNegativeButton("Cancel", (sender, e) => { /* cancel things */ }).Create();
alertDialog.Show();
// you can customize your AlertDialog, like sovar tvMessage = alertDialog.FindViewById<TextView>(Android.Resource.Id.Message);tvMessage.TextSize = 13;// ...
Dialog(activity!!, R.style.LoadingIndicatorDialogStyle).apply {// requestWindowFeature(Window.FEATURE_NO_TITLE)setCancelable(true)setContentView(R.layout.define_your_custom_view_id_here)
//access your custom view buttons/editText like below.zval createBt = findViewById<TextView>(R.id.clipboard_create_project)val cancelBt = findViewById<TextView>(R.id.clipboard_cancel_project)val clipboard_et = findViewById<TextView>(R.id.clipboard_et)val manualOption =findViewById<TextView>(R.id.clipboard_manual_add_project_option)
//if you want to perform any operation on the button do like this
createBt.setOnClickListener {//handle your button click hereval enteredData = clipboard_et.text.toString()if (enteredData.isEmpty()) {Utils.toast("Enter project details")} else {navigateToAddProject(enteredData, true)dismiss()}}
cancelBt.setOnClickListener {dismiss()}manualOption.setOnClickListener {navigateToAddProject("", false)dismiss()}show()}
MaterialAlertDialogBuilder(context).setMessage("Are you sure you want to delete this entry?").setPositiveButton("Delete") { dialog, which ->// Respond to positive button press}.setNegativeButton("Cancel") { dialog, which ->// Respond to positive button press}.show()
使用组成1.0.x,您可以使用:
val openDialog = remember { mutableStateOf(true) }
if (openDialog.value) {AlertDialog(onDismissRequest = {// Dismiss the dialog when the user clicks outside the dialog or on the back// button. If you want to disable that functionality, simply use an empty// onCloseRequest.openDialog.value = false},title = null,text = {Text("Are you sure you want to delete this entry?")},confirmButton = {TextButton(onClick = {openDialog.value = false}) {Text("Delete")}},dismissButton = {TextButton(onClick = {openDialog.value = false}) {Text("Cancel")}})}
AlertDialog.Builder(this).setTitle("Title").setPositiveButton("Yes"){ dialog, which ->
}.setNegativeButton("No", null).setMessage("Your given alert message...").show()