I've been googling for hours and tried countless things but I just can't get this to work...
This is MyFragment.java
:
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);
}
}
}
And this is styles.xml
:
<style name="MyAppTheme" parent="PreferenceFixTheme.Light.NoActionBar">
<item name="android:windowBackground">@color/background</item>
<item name="android:colorBackground">@color/background</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="preferenceCategory_marginBottom">0dp</item>
</style>
<style name="MyAppTheme.Dialog">
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
This almost works as I expect it... The only problem is that calling window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
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 colorPrimaryDark
.
If I remove that window.setLayout(...)
line, the status bar will keep the colorPrimaryDark
but the dialog size will be the default (a small square on the middle of the screen).
In the same place I call window.setLayout(...)
, I tried putting the following code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(ContextCompat.getColor(getActivity, R.color.primary_dark));
}
This sets the status bar color to colorPrimaryDark
but it overlaps both the status and navigation bar.
I just can't get fullscreen without overlapping the status and navigation bars and keep colorPrimaryDark
on the status bar.
A few questions I've found with the same problem but I couldn't get the suggestions to work. Neither have an accepted answer: