Search code examples
androiddialogandroid-dialogfragment

How to customize dialog fragment title with image view and button?


I have a dialog fragment where i need to show call log details of a person on call log list item click. I need to show display photo and a button instead of title of dialog fragment. I also tried to remove title and put photo and button but width is wrapping the content and dialog size shrinks. I need width to fill parent, or match as the parent activity.


Solution

  • My problem is fixed. Before i was trying to fix layout in xml,now i added layout width and height in the onStart method of my dialog fragment and removed title using FEATURE_NO_TITLE flag. Here is the code :

    public Dialog onCreateDialog(Bundle savedInstanceState) {
            Dialog dialog = super.onCreateDialog(savedInstanceState);
    
            // request a window without the title
            dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    
            return dialog;
        }
        @Override
        public void onStart() {
            super.onStart();
    
    // safety check
            if (getDialog() == null) {
                return;
            }
    
            int dialogWidth =  --- // specify a value here
            int dialogHeight = --- // specify a value here
            getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
    }