Overlapping DialogFragment by Status Bar

I'm a little confused.

First, when I create a toolbar and it overlaps the status bar, I just add fitSysmtemWindow="true" to the parent XML and it works fine.

But when I create a FullScreen DialogFragment , it also overlaps the status bar. I tried adding fitSystemWindow="true" and it does not work.

Only on Android 5.0+. Did not set the status bar translucent anywhere.

Here is 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. I apologize for my poor English.

+7
android android-layout android-dialogfragment
source share
3 answers

I had the same problem. I resolved it by adding a 25dp indent to the top of my root view of the dialog fragment to make sure it does not 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 utility method that I use to convert dp to px can be found here Convert pixels to dp

+2
source share

In your styles:

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

In the dialog box

 new Dialog(builder.context, R.style.MyDialog); 
+1
source share

This can 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 it if necessary.

 ActionBar actionBar = getActionBar(); actionBar.hide(); 

The above code displays the status bar for devices 4.1 and above

0
source share

All Articles