Full width Dialog

2019-08-31 00:58发布

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:

enter image description here

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条回答
Deceive 欺骗
2楼-- · 2019-08-31 01:28

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;
查看更多
登录 后发表回答