- 一种方法是在dialog的onCreate里面加上
private void initWindow() {
Window win = this.getWindow();
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
win.setAttributes(lp);
}
但是这么改是在自定义的继承自dialog里面才能这么写
有时我们可能只是简单的,这样写
final AlertDialog dialog = new AlertDialog.Builder(activity,R.style.dialog)
.setView(view1)
.create();
dialog.show();
- 那么就是第二种方法,在dialog.show()之后再调用以下的代码
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
dialog.onWindowAttributesChanged(lp);
window.setAttributes(lp);