自定义dialog使得宽度为屏幕的宽度

        mBuilder = new AlertDialog.Builder(context);
        mBuilder.setView(layoutView);
        dialog = mBuilder.create();
        dialog.show();
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.y = 0;
        dialogWindow.setAttributes(lp);

设置dialog为屏幕宽度必须在show之后设置

你可能感兴趣的:(自定义dialog使得宽度为屏幕的宽度)