• 一种方法是在dialog的onCreate里面加上
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    private 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)
    但是这么改是在自定义的继承自dialog里面才能这么写
    有时我们可能只是简单的,这样写
    1
    2
    3
    4
    final 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
    16
    Window 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)