<span style="font-size:18px;">//创建背景透明的对话框 AlertDialog.THEME_HOLO_LIGHT
AlertDialog.Builder b = new AlertDialog.Builder(myContext.getApplicationContext(), AlertDialog.THEME_HOLO_LIGHT);
dialog = b.create(); </span>
网上还有一种,但是在android5.0以上,就不能让背景透明了,实际上他们只是让对话框的内容透明
<pre name="code" class="java"><span style="white-space:pre"> </span>//获取dialog的布局属性
WindowManager.LayoutParams wmParams = dialog.getWindow().getAttributes();
//wmParams.format = PixelFormat.TRANSPARENT; 内容全透明
wmParams.format = PixelFormat.TRANSLUCENT; 内容半透明
wmParams.alpha=0.1f; 调节透明度,1.0最大
//dialog设置各种属性dialog.getWindow().setAttributes(wmParams);
经实践检测,即使是new AlertDialog.Builder(myContext.getApplicationContext(), AlertDialog.THEME_HOLO_LIGHT);也不能使所有android设备透明,有些android盒子,就还是留有白色背景,解决方法
AlertDialog.Builder b = new AlertDialog.Builder(myContext.getApplicationContext(), R.style.NoBackGroundDialog);
dialog = b.create();
<style name="NoBackGroundDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
这里不管是Theme.Holo.Light.Dialog,还是继承其他parent,例如Theme.DeviceDefault.Dialog,都可以透明!!!