I am trying to create a DialogFragment with a width of MATCH_PARENT so the dialog is nearly full screen (leaving the padding around the edges for the floating look). I have see
this answer help me How to set DialogFragment's width and height?
int width = activity.getResources().getDisplayMetrics().widthPixels;
int height = activity.getResources().getDisplayMetrics().heightPixels;
content.setLayoutParams(new LinearLayout.LayoutParams(width, height));
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE,android.R.style.Theme_Holo_Light);
}
The best solution I found was to set the width or minWidth to some arbitrarily large value to ensure it fills the screen. I don't like this solution, but I haven't seen anything better.
In my code, I was wanting a fullscreen dialog, but still show the notification bar at the top of the screen, so I'm using:
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar);
This makes it fullscreen, but I'm not using a fullscreen style so that I keep the notification bar.
Hope it helps someone!