How to customize the dialog header layout

In android, can I customize the header layout (icon + text) in the dialog box? Or can I just set the string value of the header text?

Thanks.

+3
source share
2 answers

You can change the title of the dialog box if you set your own layout for both the dialog and the title. I used this method only to completely remove the header, but this should work for a custom header:

dialog = new Dialog(context);
Window window = dialog.getWindow();
window.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.my_dialog_layout);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);

It's all more complicated (since you also need to customize the layout of the dialog box), but it's easier than subclassing Dialog.

+8
source

Dialog, , , AlertDialog ( , Dialog), -

 class MyDialog extends AlertDialog {
     public MyDialog(Context ctx) {
        super(ctx);
        LayoutInflater factory = LayoutInflater.from(context);
        View view = factory.inflate(R.layout.dialog_layout, null);
        setView(view);
        setTitle("MyTitle");
        setIcon(R.drawable.myicon);
     }
 }
+1

Source: https://habr.com/ru/post/1726160/


All Articles