<style name="mydialog" 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:backgroundDimEnabled">true</item>
<!-- 模糊 -->
</style>
private Window newDialogView() {
if (mDialog == null) {
mDialog = new Dialog(this, R.style.mydialog);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
mDialog.show();
mDialog.setCanceledOnTouchOutside(true);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
Window win = mDialog.getWindow();
WindowManager.LayoutParams lp = win.getAttributes();
// lp.alpha = 0.9f;
win.setAttributes(lp);
// WindowManager.LayoutParams.FLAG_DIM_BEHIND 背景渐变
// WindowManager.LayoutParams.FLAG_BLUR_BEHIND 背景模糊
win.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
return win;
}
private void dismissDialog() {
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND);
mDialog.dismiss();
}
使用时window = newDialogView();
window.setContentView(R.layout.game_player);