通過搜索引擎找了不少答案,但是沒有一個能解決我的問題,大多數人的需求都是去掉黑色背景,然後只能自己嘗試。
最後通過代碼來設置實現了我需要的效果。
<style name="dialog" >
<item name="android:windowNoTitle">true</item>
</style>
// style需要自己寫,只用消除title屬性就夠了,也不用設置parent
Dialog dialog = new Dialog(context,R.style.dialog);
dialog.setContentView(R.layout.dialog);
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
// 設置寬高爲match_parent,不要去算出來屏幕寬高再賦值哦,因爲有些
// 有虛擬按鍵的手機上計算出來的高度不一定準確,所以dialog不會全屏
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.heigth = WindowManager.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(params);
// 設置dialog距屏幕的邊距都爲0
dialog.getWindow().getDecorView().setPadding(0,0,0,0);
dialog.show();
需要背景是什麼顏色,就在dialog的xml根佈局中設置吧O(∩_∩)O!