Thursday, January 27, 2022

How we use simple Alert Dialog Box in android studio

Add above the OnCreate method:

private ProgressDialog progressDialog;

Add in the OnCreate method:

ProgressDialog progressDialog = new ProgressDialog(this);

than add this code after this method:
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_baseline_warning_24)
.setTitle("Exit")
.setMessage("Are you want to exit from this app!")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).show();




No comments:

Post a Comment