DialogFragment overlap by status bar
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.
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
In your styles:
<style name="MyDialog" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
In your dialog:
new Dialog(builder.context, R.style.MyDialog);
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
链接地址: http://www.djcxy.com/p/30162.html上一篇: Redux减速器/状态