android对话框代码中设置背景为透明
16lz
2021-01-23
//创建背景透明的对话框 AlertDialog.THEME_HOLO_LIGHTAlertDialog.Builder b = new AlertDialog.Builder(myContext.getApplicationContext(), AlertDialog.THEME_HOLO_LIGHT);dialog = b.create();
网上还有一种,但是在android5.0以上,就不能让背景透明了,实际上他们只是让对话框的内容透明
//获取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();
这里不管是Theme.Holo.Light.Dialog,还是继承其他parent,例如Theme.DeviceDefault.Dialog,都可以透明!!!
更多相关文章
- android 背景边框变圆角的几种方法
- android按行读取文件内容的几个方法
- android中实现背景图片颜色渐变方法
- android PopupWindow 阴影背景 、动画 、点击显示、隐藏
- Android TextView带背景图片和自定义边框
- android 阻塞 对话框 完全阻塞 停止主进程类似于window MessageB
- Android在配置文件中配置Button再不同情况下的的背景
- Android提高篇内容整理
- ListView 输入法框遮挡内容