一、在style中定义样式:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Transparent"> <item name="android:windowBackground">@color/transparent_background</item> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style> </resources>
其中transparent_background为颜色值:#50000000,透明度为50
二、代码中定义Dialog时添加样式:
final Dialog dialog = new Dialog(this,R.style.Transparent);
------------------------------------分割线------------------------------------
全屏显示Dialog的设置
下面是Dialog的style:
<!-- 全屏dialog样式 左右插入 --> <style name="mydialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowBackground">#FFFFFF</item> </style>
Dialog dialog = new Dialog(Activity.this, R.style.mydialog); dialog.setContentView(R.layout.layout); LayoutParams lay = dialog.getWindow().getAttributes(); setParams(lay); dialog.show();
private void setParams(LayoutParams lay) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); Rect rect = new Rect(); View view = getWindow().getDecorView(); view.getWindowVisibleDisplayFrame(rect); lay.height = dm.heightPixels - rect.top; lay.width = dm.widthPixels; }