Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set icon for dialog in Android

Tags:

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");
like image 849
D T Avatar asked Jul 11 '12 10:07

D T


1 Answers

You can add an icon with the following code:

Dialog dialog = new Dialog(context);

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

dialog.show();

See "Icons in custom dialogs android".

like image 92
D T Avatar answered Sep 28 '22 07:09

D T