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.

3 Answers 3

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

1
  • 1
    Unfortunately this solution is bad because Status Bar size is differs from device to device, so it is really bad practise (see youtu.be/_mGDMVRO3iE?t=1074). Commented Mar 17, 2019 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

1
  • 2
    thank but anyway to fix this problem without hide the status bar.
    – Math Burn
    Commented Oct 30, 2015 at 5:37
0

In your styles:

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

In your dialog:

new Dialog(builder.context, R.style.MyDialog);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.