Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place an icon into the title of a custom dialog

I'd like to place a drawable into a dialogs title bar. I tried the following:

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.some_icon);
dialog.setTitle(R.string.my_dialog_title);
dialog.setContentView(R.layout.my_dialog_layout);
...

The icon doesn't show up but the title moves a little to the right. It seems the dialog reserves space for the drawable but doesn't draw it. I tried several different icons (also from the android resources) but non of them worked.

like image 329
Tom Avatar asked Nov 26 '10 11:11

Tom


People also ask

What is dialog explain Alert dialog with example?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. DatePickerDialog or TimePickerDialog. A dialog with a pre-defined UI that allows the user to select a date or time.


1 Answers

Call setFeatureDrawableResource() after show().

No idea why this works. :)

like image 55
Reuben Scratton Avatar answered Sep 17 '22 23:09

Reuben Scratton