DialogFragment 透明全屏设置终极实用办法
2016-06-22 19:30
281 查看
今天在项目中需要用到DialogFragment,并且需要全屏透明;
苦逼的是怎么弄两边都会有一点间距;
这是因为DialogFragment 弹出框默认是在屏幕的中央,左右还有留白,那么怎么样才能将这左右的留白去掉呢?
红色是我想去掉的地方
答案很简单(但是我还没弄明白):
在你的DialogFragment加上上面这段话就可以了;
我还没搞懂原理,如果你明白原理请在评论里留言,谢谢!
另外设置透明就比较简单了,这是我的style:
苦逼的是怎么弄两边都会有一点间距;
这是因为DialogFragment 弹出框默认是在屏幕的中央,左右还有留白,那么怎么样才能将这左右的留白去掉呢?
红色是我想去掉的地方
答案很简单(但是我还没弄明白):
@Override public void onStart() { super.onStart(); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm ); getDialog().getWindow().setLayout( dm.widthPixels, getDialog().getWindow().getAttributes().height ); }
在你的DialogFragment加上上面这段话就可以了;
我还没搞懂原理,如果你明白原理请在评论里留言,谢谢!
另外设置透明就比较简单了,这是我的style:
<style name="TranslucentNoTitle" parent="android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFullscreen">true</item> <item name="android:colorBackgroundCacheHint">@null</item> </style>
相关文章推荐
- 【洛谷1031 均分纸牌】【模拟】
- JSON详细学习之JSONObject in JAVA
- Java IO流的操作规律
- 走进JVM【二】理解JVM内存区域
- iOS开发-网络框架-b
- Struts 2再曝远程代码执行漏洞S2-037
- keepalived高可用haproxy/nginx
- epoll详解
- Jenkins Slave前台运行robotframework测试用例
- R语言实战:机器学习与数据分析源代码5
- debian 安装 android studio 环境
- 游戏敏捷开发项目管理之我见(二)
- annotation-config, annotation-driven, compont-scan 区别
- 在myeclipse中如何修改Web Context-root,就是部署在Tomcat的webapps目录下的那个文件夹名字
- Systemd入门教程:命令篇
- 英特尔实感3D摄像头
- Maven中央仓库
- 151. Reverse Words in a String
- 利用fork循环创建进程
- QtQuick UI 问答