AlertDialog自定义
来源:互联网 发布:bp神经网络java代码 编辑:程序博客网 时间:2024/04/30 10:14
AlertDialog的自定义其实网上很多了,但是有一个坑却很少见人提及。先看下Java代码部分:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DialogTheme);builder.setView(R.layout.dialog_layout);builder.create().show();
有两处地方需要注意下:
- R.style.DialogTheme 这里是重点,下面我会放上代码;
- R.layout.dialog_layout这里就是你自定义的Dialog的视图文件了,不需要多说;
R.style.DialogTheme代码:
<style name="DialogTheme" parent="AlertDialog.AppCompat"> <!--去掉AlertDialog的背景--> <item name="android:windowBackground">@android:color/transparent</item> <!--浮现在activity之上,如果不设置该属性,那么对话框的宽度就会变宽--> <item name="android:windowIsFloating">true</item></style>
Dialog主题中第一行的代码,是设置透明背景,主要是为了实现“网易云发现新版本”的那种Dialog效果,如下所示:
第二行的代码设置Dialog浮动在Activity上是为了解决对话框宽度会占据整个屏幕的问题,虽然可以在布局中设置margin来使对话框宽度距离屏幕边缘有个距离,但是对于强迫症患者肯定不喜欢这个样子的,比如我。所以这句代码就是解决方法。
谢谢观看
该项目Sunshine已放在GitHub,这是其中一篇开发记录,更多开发记录文章请点击该项目查看。
阅读全文
0 0
- 自定义 alertDialog
- 自定义AlertDialog
- AlertDialog自定义
- 自定义AlertDialog
- 自定义 AlertDialog
- 自定义AlertDialog
- 自定义Alertdialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- 自定义AlertDialog
- AlertDialog 自定义
- 自定义AlertDialog
- 自定义alertDialog
- LayoutParams
- ios 基础知识点总结 (二)
- MAC-终端命令大全
- Maven+jetty启动调试时遇到source not found,容易坑死一大批初学者
- 资讯精选 | 吴京、赵薇都被吸引来了——1亿人次参与的奇迹_就差你了!
- AlertDialog自定义
- 运放构成的电压跟随器
- 控制ExpandableListView展开和关闭
- Oracle 11g 安装教程,足够详细
- 安装jdk 错误1721 windows installer程序包有问题
- WPF之Binding深入探讨
- RHEL 5下配置Hadoop集群:java.net.NoRouteToHostException: No route to host问题的解决
- access denied for xxx@localhost
- Tomcat安装之在Mac环境下配置tomcat9