AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create(); View view = LayoutInflater.from(getContext()).inflate(R.layout.version_update, null); alertDialog.setView(view); alertDialog.show(); //改变弹框宽度 大小 必须放在show方法下面才能起作用 alertDialog.getWindow().setLayout(DensityUtil.dip2px(getContext(), 248), DensityUtil.dip2px(getContext(), 270));
//宽度充满
Dialog dialog = new Dialog(getContext()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.activity_view); dialog.show(); dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0); dialog.getWindow().setGravity(Gravity.BOTTOM); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE)); //dialog.getWindow().setWindowAnimations(); WindowManager.LayoutParams a = dialog.getWindow().getAttributes(); // a.height = WindowManager.LayoutParams.MATCH_PARENT; a.width = WindowManager.LayoutParams.MATCH_PARENT; dialog.getWindow().setAttributes(a);