D T D T - 4 months ago 8
Android Question

How to set icon for dialog in Android

I want to customize a dialog in Android.
I know how to set the title for dialog:

dialog.setTitle("O message");


Now I want to set the icon in front of the title.
How can I achieve this?

Dialog dialog;
dialog = new Dialog(this);
dialog.setContentView(R.layout.layouterror22);
dialog.setTitle("O message");

D T D T
Answer

You can add an icon with the following code:

Dialog dialog = new Dialog(context);

dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Dialog Title");
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.your_icon);    
dialog.show();

See "Icons in custom dialogs android".

Comments