網上大多數介紹的實現方式就是在styles.xml中添加<item name="android:windowFullscreen">true</item>
這個屬性,可是本身按照操做很差使,後來本身嘗試去作一下,總結方法以下代碼android
Dialog dialog = new Dialog(this, R.style.Dialog); dialog.show(); LayoutInflater inflater = LayoutInflater.from(this); View viewDialog = inflater.inflate(R.layout.adapter_list, null); Display display = this.getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); //設置dialog的寬高爲屏幕的寬高 ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(width, height); dialog.setContentView(viewDialog, layoutParams);
主要重要的步驟就是設置Dialog的寬高爲屏幕的寬高,這樣就能夠實現Dialog的全屏顯示。this