DialogFragment fullscreen shows padding on sides

ahmad picture ahmad · Aug 30, 2013 · Viewed 44.2k times · Source

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.

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.

Answer

ahmad picture ahmad · Sep 1, 2013

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>

Usage:

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

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