How to set icon for dialog in Android

前端 未结 1 1830
北海茫月
北海茫月 2021-02-15 10:00

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

1条回答
  •  无人及你
    2021-02-15 10:46

    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".

    0 讨论(0)
提交回复
热议问题