How to make DialogFragment width to Fill_Parent How to make DialogFragment width to Fill_Parent android android

How to make DialogFragment width to Fill_Parent


This is the solution I figured out to handle this issue:

@Overridepublic Dialog onCreateDialog(Bundle savedInstanceState) {    Dialog dialog = super.onCreateDialog(savedInstanceState);        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);    return dialog;}@Overridepublic void onStart() {    super.onStart();    Dialog dialog = getDialog();    if (dialog != null) {       dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);       dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));    }}

Edit:

You can use the code below in onCrateView method of Fragment before return the inflated view.

getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));


Have you tried using the answer of Elvis from How to make an alert dialog fill 90% of screen size?

It is the following:

dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

Update:

Above code should be added inside onStart() method of the DialogFragment.


This is worked for me

Create your custom style :

   <style name="DialogStyle" parent="Base.Theme.AppCompat.Dialog">    <item name="android:windowMinWidthMajor">97%</item>    <item name="android:windowMinWidthMinor">97%</item>   </style>

You can also try use the right parent to match your other dialogs. for example parent="ThemeOverlay.AppCompat.Dialog" and so on.

Use this style in your dialog

public class MessageDialog extends DialogFragment {@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogStyle);}// your code }