Android gets rid of DialogFragment floating field

I show a dialog box in my application, and I notice that even when I set the y position of the fragments at the bottom of the screen, a visible field still appears:

        Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        windowParams.y = size.y;

In the next screenshot, you see that the light blue (my dialogical fragment) is still at some distance from the bottom of the screen, despite the fact that it is installed at the bottom of the screen. How to remove this field?

margins

+4
source share
2 answers

The solution is to add this line:

setStyle(DialogFragment.STYLE_NO_FRAME, 0);
+4
source

To avoid an extra field in the lower, upper, left and right uses below the lines of code.

//Dialog fragment will be shown at the bottom of screen 

//if you want to show on entire screen just comment it

getDialog().getWindow().setGravity(Gravity.BOTTOM);

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = getDialog().getWindow();



lp.copyFrom(window.getAttributes());

 //This makes the dialog take up the full width



lp.width = WindowManager.LayoutParams.MATCH_PARENT;

//For full height set it to MATCH_PARENT else WRAP_CONTENT



lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

window.setAttributes(lp);
0
source

All Articles