How to show appropriate icon on dialog box

I tend to use AlertDialog.Builder like they show in the official doc example

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();
       }
   })
   //Set your icon here
   .setTitle("Alert!")
   .setIcon(R.drawable.icon);
AlertDialog alert = builder.create();
 alert.show();//showing the dialog

As for the actual icon look inside your sdk folder/platforms/android version #/data/res/drawable-mdpi or something


In order to set the default Dialog icons use:

.setIcon(android.R.drawable.ic_dialog_alert)

There are a few more icons available:

  • android.R.drawable.ic_dialog_dialer
  • android.R.drawable.ic_dialog_info
  • android.R.drawable.ic_dialog_email
  • android.R.drawable.ic_dialog_map