final Dialog dialog = new Dialog(this, R.style.theme_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_name);
dialog.setCancelable(false);
dialog.getWindow().setGravity(Gravity.TOP);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
上面的代码约占90%的宽度,但我想要100%。Android:Dialog占据100%宽度
'ViewGroup.LayoutParams.MATCH_PARENT'和'WindowManager.LayoutParams.MATCH_PARENT'都具有相同的恒定值,因此这将不会有任何效果 –