8

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.

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
Math Burn
  • 89
  • 1
  • 6

3 Answers3

1

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

Community
  • 1
  • 1
aaronmarino
  • 3,723
  • 1
  • 23
  • 36
  • 1
    Unfortunately this solution is bad because Status Bar size is differs from device to device, so it is really bad practise (see https://youtu.be/_mGDMVRO3iE?t=1074). – Kiryl Tkach Mar 17 '19 at 16:32
0

This may help:

View decorView = getWindow().getDecorView();

// Hide the status bar.

int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;

decorView.setSystemUiVisibility(uiOptions);

// Remember that you should never show the action bar if the // status bar is hidden, so hide that too if necessary.

ActionBar actionBar = getActionBar();

actionBar.hide();

The above code diables status bar for devices 4.1 and higher

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
0

In your styles:

<style name="MyDialog" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>

In your dialog:

new Dialog(builder.context, R.style.MyDialog);
Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110