去除自定义AlertDialog黑边
来源:互联网 发布:两张表格怎么比对数据 编辑:程序博客网 时间:2024/05/01 20:50
http://blog.csdn.net/mwj_88/article/details/45482421
1、现象描述
- View _view = LayoutInflater.from(getActivity()).inflate(R.layout.alertdialog_schoolcourse, null);
- AlertDialog _ad = new AlertDialog.setView(_view).Builder(getActivity()).create();
- _ad.requestWindowFeature(Window.FEATURE_NO_TITLE);
- _ad.show();
看到黑边了吧,真丑。
2、将就的解决方案
- View _view = LayoutInflater.from(getActivity()).inflate(R.layout.alertdialog_schoolcourse, null);
- AlertDialog _ad = new AlertDialog.Builder(getActivity()).create();
- _ad.requestWindowFeature(Window.FEATURE_NO_TITLE);
- _ad.setView(_view, 0, 0, 0, 0);
- _ad.show();
虽然上下的黑边不见了,但是四周仍有个黑框。
3、更好的解决方案
通过样式文件把背景设置为透明。
- View _view = LayoutInflater.from(getActivity()).inflate(R.layout.alertdialog_schoolcourse, null);
- AlertDialog _ad = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.Theme_Transparent)).create();
- _ad.requestWindowFeature(Window.FEATURE_NO_TITLE);
- _ad.setView(_view);
- _ad.show();
样式任选其一即可:
- <style name="Theme_Transparent" parent="@android:Theme.DeviceDefault.Light.Dialog">
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowNoTitle">true</item>
- </style>
- </style>
- <item name="android:windowFrame">@null</item>
- </style>
效果图:
4、Perfect解决方案
上面的解决方案会导致AlertDialog无故变宽,而且如果你想加个圆角背景,会发现根本没效果~
其实你只需要了解一点:
setView()和setContentView()的区别:setView()只会覆盖AlertDialog的Title和Button之间的部分,而setContentView()则会全部覆盖。
注意:setContentView()必须在show()后面调用。
要改变AlertDialog的尺寸:只需调用ad.getWindow().setLayout(200, 250);此方法同样也需要在show()后调用,否则无效。
0 0
- 去除自定义AlertDialog黑边
- AlertDialog去除黑边自定义布局
- 去除自定义alertdialog(dialog)黑边
- 笔记107--去除自定义AlertDialog黑边
- Android中自定义AlertDialog,去除黑,白边框
- android 自定义Dialog去除黑边
- 自定义dialog并且去除黑边
- Android2.3 自定义AlertDialog布局 去上下黑边
- Android自定义AlertDialog去掉黑边的方法
- 自定义AlertDialog去除黑色背景
- android_自定义dialog去除黑边_快捷方法
- 【Android】自定义透明dialog 去除边缘阴影 黑边
- 最简单自定义dialog去除dialog黑边方法
- android AlertDialog去除黑边白边自定义布局
- 去除dialog的黑边
- AlertDialog出现黑边快速解决方法
- [经验之谈]自定义的Dialog教你怎么去除黑边框
- vc自画窗体 黑边去除
- eclipse中svn插件的安装
- Volley StringRequest和JSONObjectRequest使用几个细节
- 6.Hero In Maze
- 新大陆--markdown 以后可以开心的写博客了
- 面向对象的特征有哪些方面
- 去除自定义AlertDialog黑边
- 偶数求和
- Spark-SparkSQL深入学习系列四(转自OopsOutOfMemory)
- volatile关键字。编译器不优化,多线程会改。防止随时变动的
- boost bimap 学习笔记
- iOS开发之基础视图——UISegmentedControl
- LinearLayout中的weight属性的计算
- UniversalImageLoader源码解读05-磁盘缓存
- 数据库为DATETIME java存值