dialog更改宽高
- 一种方法是在dialog的onCreate里面加上但是这么改是在自定义的继承自dialog里面才能这么写
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22private void initWindow() {
<<<<<<< HEAD
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);
}
=======
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);
}
>>>>>>> 3bc004a (init local)
有时我们可能只是简单的,这样写1
2
3
4final AlertDialog dialog = new AlertDialog.Builder(activity,R.style.dialog)
.setView(view1)
.create();
dialog.show(); - 那么就是第二种方法,在dialog.show()之后再调用以下的代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16Window window = dialog.getWindow();
<<<<<<< HEAD
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);
=======
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);
>>>>>>> 3bc004a (init local)
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 七夜的小屋!