I am little confused.
At first, when I create a toolbar and it get overlapped by status bar, I just add fitSysmtemWindow="true"
in parent XML and it work just fine.
But when I create FullScreen DialogFragment
, It get overlapped by status bar too. I tried to add fitSystemWindow="true"
and it doesn't work.
Only present on android 5.0+. Didn't set status bar to translucent anywhere.
Here my DialogFragment code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_create_bill_dialog,container, false);
return view;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
Thanks.Sorry for my bad Eng.
This method is deprecated. androidx.
DialogFragment is Fragment so you have to manage them like Fragment. You can insert them in your layout for example. But you definitely have to manage them as you manage fragment. The only difference is when creating them you use onCreateDialogFragment instead of onCreate and onCreateView.
Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.
tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.
I had the same problem. I resolved it by adding 25dp padding to the top of my Dialog Fragment root view, to ensure it didn't overlap with the status bar.
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//If showing as a dialog, add some padding at the top to ensure it doesn't overlap status bar
if (getDialog() != null) {
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
view.setPadding(0, (int)PresentationUtils.convertDpToPixel(25f, getContext()), 0, 0);
view.requestLayout();
}
...
}
Btw, the util method I'm using for converting dp to px can be found here Converting pixels to dp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With