AlertDialog Displays Landscape-Sized View with Orientation in Landscape

本秂侑毒 提交于 2019-12-03 20:42:26

You could try getting the screen dimensions like this:

Display display = getWindowManager().getDefaultDisplay(); 
int mwidth = display.getWidth();
int mheight = display.getHeight();

And then alter the Dialog like this:

AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)

d.show();

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = mwidth;
lp.height = myheight;

//change position of window on screen
lp.x = mwidth/2; //set these values to what work for you; probably like I have here at
lp.y = mheight/2;        //half the screen width and height so it is in center

//set the dim level of the background
lp.dimAmount=0.1f; //change this value for more or less dimming

d.getWindow().setAttributes(lp);

//add a blur/dim flags
d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Also, you say you are inflating a custom layout. Have you tried tinkering with the layout_height and layout_width of the views in that layout to see if that makes a difference?

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