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'都具有相同的恆定值,因此這將不會有任何效果 –