Full width Dialog

久未见 提交于 2019-12-12 04:16:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!