popwindow

2018-04-17  本文已影响7人  ae12
public void showDialog() {
    dialog = new Dialog(this, R.style.BottomDialog);
    inflate = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null);
    choosePhoto = (TextView) inflate.findViewById(R.id.choosePhoto);
    takePhoto = (TextView) inflate.findViewById(R.id.takePhoto);
    cancel = (TextView) inflate.findViewById(R.id.btn_cancel);
    choosePhoto.setOnClickListener(this);
    takePhoto.setOnClickListener(this);
    cancel.setOnClickListener(this);
    dialog.setContentView(inflate);
    Window dialogWindow = dialog.getWindow();
    dialogWindow.setGravity(Gravity.BOTTOM);
    // WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    //获得window窗口的属性
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    //设置窗口宽度为充满全屏
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    //设置窗口高度为包裹内容
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    //将设置好的属性set回去
    dialogWindow.setAttributes(lp);
    //将自定义布局加载到dialog上
    dialog.setContentView(inflate);
    dialog.show();
}
上一篇下一篇

猜你喜欢

热点阅读