只需要在dialogshow()后面加上后面代码即可,获取屏幕宽高。
dialog.show(); WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.width = (int)(display.getWidth()*0.8); //设置宽度 dialog.getWindow().setAttributes(lp);