How to make DialogFragment fullscreen without overlapping status bar/navigation bar and mantain status bar color?
<p>I've been googling for hours and tried countless things but I just can't get this to work...</p>

<p>This is <code>MyFragment.java</code>:</p>

<pre><code>public class MyFragment extends DialogFragment {

    public MyFragment() {
        // Required empty public constructor
    }

    public static MyFragment newInstance() {
        MyFragment newFragment = new LoginDialogFragment();
        newFragment.setCancelable(false);
        return newFragment;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new Dialog(getActivity(), R.style.MyAppTheme_Dialog);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Window window = getDialog().getWindow();

        if (window != null) {
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            window.setWindowAnimations(R.style.MyAppTheme_Dialog);
        }
    }

}
</code></pre>

<p>And this is <code>styles.xml</code>:</p>

<pre><code>&lt;style name="MyAppTheme" parent="PreferenceFixTheme.Light.NoActionBar"&gt;
    &lt;item name="android:windowBackground"&gt;@color/background&lt;/item&gt;
    &lt;item name="android:colorBackground"&gt;@color/background&lt;/item&gt;
    &lt;item name="colorPrimary"&gt;@color/primary&lt;/item&gt;
    &lt;item name="colorPrimaryDark"&gt;@color/primary_dark&lt;/item&gt;
    &lt;item name="colorAccent"&gt;@color/accent&lt;/item&gt;
    &lt;item name="preferenceCategory_marginBottom"&gt;0dp&lt;/item&gt;
&lt;/style&gt;

&lt;style name="MyAppTheme.Dialog"&gt;
    &lt;item name="android:backgroundDimEnabled"&gt;false&lt;/item&gt;
    &lt;item name="android:windowBackground"&gt;@null&lt;/item&gt;
    &lt;item name="android:windowContentOverlay"&gt;@null&lt;/item&gt;
    &lt;item name="android:windowEnterAnimation"&gt;@anim/slide_up&lt;/item&gt;
    &lt;item name="android:windowExitAnimation"&gt;@anim/slide_down&lt;/item&gt;
    &lt;item name="android:windowFrame"&gt;@null&lt;/item&gt;
    &lt;item name="android:windowIsFloating"&gt;true&lt;/item&gt;
    &lt;item name="android:windowSoftInputMode"&gt;stateUnspecified|adjustPan&lt;/item&gt;
&lt;/style&gt;
</code></pre>

<p>This almost works as I expect it... The only problem is that calling <code>window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);</code> to fill the whole screen (minus the status/navigation bars) changes the status bar color to black. When I close the dialog, it changes back to <code>colorPrimaryDark</code>.</p>

<p>If I remove that <code>window.setLayout(...)</code> line, the status bar will keep the <code>colorPrimaryDark</code> but the dialog size will be the default (a small square on the middle of the screen).</p>

<p>In the same place I call <code>window.setLayout(...)</code>, I tried putting the following code:</p>

<pre><code>if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(getActivity, R.color.primary_dark));
}
</code></pre>

<p>This sets the status bar color to <code>colorPrimaryDark</code> but it overlaps both the status and navigation bar.</p>

<p>I just can't get fullscreen without overlapping the status and navigation bars and keep <code>colorPrimaryDark</code> on the status bar.</p>

<p>A few questions I've found with the same problem but I couldn't get the suggestions to work. Neither have an accepted answer:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/28284608/fullscreen-dialogfragment-with-translucent-statusbar">Fullscreen DialogFragment with translucent StatusBar</a></li>
<li><a href="https://stackoverflow.com/questions/37433448/android-full-screen-dialog-fragment-like-calendar-app">Android full screen dialog fragment like calendar app</a></li>
</ul>