DialogFragment fullscreen shows padding on sides

后端 未结 11 1589
囚心锁ツ
囚心锁ツ 2020-12-05 00:22

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_pa

相关标签:
11条回答
  • 2020-12-05 00:46
    <style name="WideDialog" parent="Theme.AppCompat.Light.DialogWhenLarge">
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowFullscreen">false</item>
            <item name="android:windowIsFloating">false</item>
        </style>
    
    @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setStyle(DialogFragment.STYLE_NORMAL, R.style.WideDialog);
        }
    
    0 讨论(0)
  • 2020-12-05 00:47

    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

    0 讨论(0)
  • 2020-12-05 00:51

    For fullscreen dialog I have posted a answer

    In this thread

    Please check this is the most efficient and shortest way. Hope this helps :)

    0 讨论(0)
  • 2020-12-05 00:57

    DialogFragment (when not told explicitly), will use its inner styles that will wrap your custom layout in it (no fullscreen, etc.).

    No need to create custom theme for this problem. Just use this method and set style and theme of your choosing:

    /* theme is optional, I am using leanback... */
    setStyle(STYLE_NORMAL, R.style.AppTheme_Leanback);
    
    0 讨论(0)
  • 2020-12-05 01:00

    I was getting huge side padding in the DialogFragment for Nexus 6p and Pixel.

    Fixed that by defining custom style as follows:

    <style name="Custom.Dialog" parent="android:Theme.DeviceDefault.Dialog.NoActionBar.MinWidth" >
            <item name="android:windowBackground">@null</item>
            <item name="android:windowIsFloating">true</item>
    </style>
    

    parent="android:Theme.DeviceDefault.Dialog.NoActionBar.MinWidth did the trick

    0 讨论(0)
提交回复
热议问题