Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no icon for alert dialog

Tags:

android

even if I don't set icon .setIcon(android.R.drawable.ic_dialog_alert) for dialog box, it is showing info icon.

How can I completely remove the icon from dialog box?

new AlertDialog.Builder(MyActivity.this)
    .setTitle(R.string.success_title)
    .setMessage(R.string.success_msg)
    .setNeutralButton("OK",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dlg, int sumthin) {
                try {
                    dlg.dismiss();
                } catch (Exception e) {
            }
        }
}).show();

Edited: Sorry everyone.. I completely remove .setIcon line from the dialog box. I forget to remove it when I paste the code here. Even I remove that I still can see the icon as information icon.

like image 979
kitokid Avatar asked Nov 29 '12 06:11

kitokid


People also ask

How do I add icons to alert dialog?

You can add an icon with the following code: Dialog dialog = new Dialog(context); dialog. requestWindowFeature(Window. FEATURE_LEFT_ICON); dialog.

What is the difference between an alert and an alert dialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .

How do I know my dialog is showing or not?

You can do it using showGeneralDialog and put dismissible property to false , using this will ensure you that you are the only one who is handling pop up, like in your any action buttons in dialog.

How do I show custom alerts?

Add custom_layout. xml in that activity in which you want to show custom alert dialog here it is added in MainActivity.


2 Answers

new AlertDialog.Builder(MyActivity.this)
    //.setIcon(android.R.drawable.i)    /// put comment on this line
    .setTitle(R.string.success_title)
    .setMessage(R.string.success_msg)
    .setNeutralButton("OK",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dlg, int sumthin) {
                try 
                {
                    dlg.dismiss();
                } catch (Exception e) {
            }
        }
}).show();
like image 118
Mehul Ranpara Avatar answered Sep 24 '22 06:09

Mehul Ranpara


Try This

new AlertDialog.Builder(MainActivity.this)
    .setIcon(null)
    .setTitle("Naeem").setMessage("Shahzad").setNeutralButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dlg, int sumthin) {
            try {
                dlg.dismiss();
            } catch (Exception e) {
            }
        }
    }).show();
like image 24
Naeem Avatar answered Sep 23 '22 06:09

Naeem