DialogFragment 全屏显示两侧的填充 [英] DialogFragment fullscreen shows padding on sides

查看:31
本文介绍了DialogFragment 全屏显示两侧的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个显示在操作栏下方的自定义 DialogFragment.到目前为止,一切都很好.对话框片段的布局参数是 match_parent 宽度和 wrap_content 高度.

I am creating a custom DialogFragment that is displayed underneath the actionbar. So far everything works great. The layout parameters for dialog fragment are match_parent for width and wrap_content for height.

我尝试了所有解决方案,包括设置布局参数 .width 以及获取显示大小和删除主题.但是,无论如何,对话框的左侧、右侧和顶部都有少量不可见的空间.我需要知道如何移除这个空间,使其与屏幕的宽度相匹配,并希望也能去掉顶部填充.

I have tried every solution including setting the layout parameters .width and by getting Display size and removing the themes. However no matter what there is a small amount of space on left, right and top side of the dialog that is invisible. I need to know how to remove this space so it actually matches the width of the screen and hopefully gets rid of the top padding as well.

推荐答案

我使用自定义对话框主题解决了这个问题.windowIsFloating true 将摆脱背景,但会在背景下添加一些额外的空间作为背景.在这种情况下,您可以使用 windowBackground @null 来擦除它.

I figured it out using custom dialog theme. windowIsFloating true will get rid of the background but will add some extra space underneath the background as a background. In which case you can use windowBackground @null to erase it.

<style name="CustomDialog" parent="@android:style/Theme.Holo.Light" >
    <item name="android:windowBackground">@null</item>
    <item name="android:windowIsFloating">true</item>
</style>

用法:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.CustomDialog);

感谢 Raghunandan,他给了我包含所有样式属性的链接.我花了一段时间,但我浏览了那个文件,发现了非常有趣的元素.一定要查看下面发布的链接以探索主题样式.

Thank you to Raghunandan who gave me the link that includes all style attributes. It took me a while but I went through that file and found very interesting elements. Definitely have a look at the link posted below to explore theme styles.

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

这篇关于DialogFragment 全屏显示两侧的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆