Android - Icon not shown in AlertDialog

It might be that you need to set the title as well. If you do not like the new layout you might want to look at this question.

AlertDialog.Builder builder = new AlertDialog.Builder(this );  
builder
    .setMessage("Repeat game?")
    .setTitle("")
    .setIcon(android.R.drawable.ic_dialog_alert)         //<--- icon does not show
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            //Yes button clicked, do something
        }
    })
    .setNegativeButton("No", null)                      //Do nothing on no
    .show();

Your title is empty, so android will not display it, therefore no icon will be shown either.

Set it to empty string:

builder.setTitle("")...<all the other stuff>

You should use something like this:

builder.setIcon(getResources().getDrawable(android.R.drawable.ic_dialog_alert));

Try this :)


You just need to add title, because the position of your icon is beside your title.

.setTitle("Attention")
.setIcon(android.R.drawable.ic_dialog_alert)  

Tags:

Android