How to show appropriate icon on dialog box

Viewed 32990

I have an application that allows the users to delete video files. When I press the delete button, I am using

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            // mycode........
            break;
        case DialogInterface.BUTTON_NEGATIVE:
            // mycode.....
            break;
        }
    }
};

But this message doesn't have a warning or delete icon as we see in android devices. Can anyone help me in getting those icons or using any other alert dialogs that can show those icons?

6 Answers

You can also set certain icon for the Alert dialog buttons as:

builder.setPositiveButtonIcon( getResources().getDrawable( drawable.ic_menu_share )

just set the title for you AlertDialog. like this:

adb.setTitle(R.string.app_name);

ful example:

AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setIcon(R.mipmap.ic_launcher_foreground);
adb.setTitle(R.string.app_name);
adb.show();
Related