一:控制Dialog 的背景方法:
1.定義一個無背景主題主題
<!--去掉背景Dialog-->
- <style name="NobackDialog" parent="@android:style/Theme.Dialog">
- <item name="android:windowBackground">@color/no_back</item>
- </style>
復制代碼
2.創建Dialog
- dialog = new Dialog(this,R.style.dialog);
- dialog.setContentVIEw(R.layout.dialog_loading);
復制代碼
or:
- dialog = new Dialog(this,R.style.NobackDialog);
- LayoutInflater mInflater = LayoutInflater.from(this);
- VIEw dialogProcessBar = mInflater.inflate(R.layout.dialog_loading,null);
- dialog.setVIEw(dialogProcessBar,0, 0, 0, 0);
復制代碼
二:控制Dialog 以及內部控件的背景方法:
- dialog = new Dialog(this,R.style.dialog);
- WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();
- // 模糊度getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); dialog.getWindow().setAttributes(lp);
- lp.alpha=0.5f;(0.0-1.0)//透明度,黑暗度為lp.dimAmount=1.0f;
復制代碼
三:去掉邊框、title 等參數
- <resources>
- <style name="dialog" parent="@android:style/Theme.Dialog">
- <item name="android:windowFrame">@null</item><!--邊框-->
- <item name="android:windowIsFloating">true</item><!--是否浮現在activity之上-->
- <item name="android:windowIsTranslucent">false</item><!--半透明-->
- <item name="android:windowNoTitle">true</item>
- <item name="android:background">@android:color/black</item>
- <item name="android:windowBackground">@null</item>
- <item name="android:backgroundDimEnabled">false</item><!--模糊-->
- </style>
- </resources>