问题
I what the Dialog to cover up the whole screen width.
Hence:
Dialog dialog = new Dialog(this);
LayoutParams params = dialog.getWindow().getAttributes();
params.height = LayoutParams.MATCH_PARENT;
params.width = LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(params);
But the result is:
Skip is a button in a parent layout (MATCH_PARENT as width and height and 10dp padding and orange background).
Even in this answer the final result has some gaps on sides.
Is there a way to cover the whole screen width without any gaps?
回答1:
The solution that worked for me was the following:
Grab the device dimensions using:
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
Then set the width of the dialog to the screen width
params.width = size.x;
来源:https://stackoverflow.com/questions/21699538/full-width-dialog