Reputation: 8021
I'm displaying a dialogfragment in my app and I notice that even when I set the fragments' y position to the bottom of the screen there's still a margin visible:
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
windowParams.y = size.y;
In the below screenshot you can see that the light blue (my dialogfragment) is still appearing some distance away from the bottom of the screen despite being set to the bottom of the screen. How do I remove this margin?
Upvotes: 4
Views: 4415
Reputation: 21
To avoid extra margin in bottom, top , left and right use below 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);
Upvotes: 0
Reputation: 8021
The solution is to add this line:
setStyle(DialogFragment.STYLE_NO_FRAME, 0);
Upvotes: 2