<style name="FullScreenDialog" parent="android:style/Theme.Dialog">
<item name="android:backgroundDimAmount">0.8</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
通过style来设置全屏、背景透明、且自定义界面的dialog。
显示一个自定义内容的对话框:
new AlertDialog.Builder(this)
.setTitle("提示")
.setView(
LayoutInflater.from(getApplicationContext())
.inflate(R.layout.login_dialog_view,
null))
.setCancelable(false)
.show();
Dialog透明度调整:
WindowManager.LayoutParams lp = dialog.getWindow()
.getAttributes();
lp.dimAmount = 0.7f;//设置对话框外部区域透明度
lp.alpha = 0.7f;//设置对话框本体背景透明度
dialog.getWindow().setAttributes(lp);
Dialog点击周围,touch事件传到盖住的界面上。
Window window = getWindow();
WindowManager.LayoutParams wl = window.getAttributes();
wl.flags = wl.flags | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
window.setAttributes(wl);
调整Dialog周围的透明度:
Window window = getWindow();
WindowManager.LayoutParams wl = window.getAttributes();
wl.dimAmount = 0.2f;
wl.flags = wl.flags | WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wl);