private AlertDialog alert;
private void closeAppDialog(Context context) {
AlertDialog.Builder exitDialog = new AlertDialog.Builder(context);
exitDialog
.setMessage("Are you sure?")
.setTitle("Exit Application?")
.setCancelable(true)
.setIcon(R.drawable.icon_close_app)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// write your code here
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//alert.dismiss(); or
// write your code here
}
});
alert = exitDialog.create();
alert.show();
}
Your Alert Dialog look like :
Download Icon: Click Me
Create an Alert Dialog with an icon
You can open an Alert Dialog via this code: