Search code examples
androidmaterial-designandroid-datepicker

white background for date picker dialog shadow


I add datepicker to my application but my problem the shadow for the dialog have white background , use Android 21 for compile .

please help me to remove white background ...

enter image description here


Solution

  • You have a "bug" in your themes.xml or styles.xml material design support library is not working properly with dialogs.

    So remove the specific dialog code or separate it in different versions.


    Trying to explain a little bit further.

    Generally when we extend the original application theme we have an themes.xml and/or styles.xml files under the values folder. In there code you will find something like these:

    Application theme:

    <style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <!-- ... other styling values ...  -->
    
        <!-- Dialog attributes -->
        <item name="dialogTheme">@style/MyTheme.Dialog</item>
        <!-- AlertDialog attributes -->
        <item name="alertDialogTheme">@style/MyTheme.Dialog</item>
    
        <!-- ... other styling values ...  -->
    </style>
    

    Custom dialog theme:

    <style name="MyTheme.Dialog" parent="@style/Theme.AppCompat.Light.Dialog">
        <!-- some styling values here -->
    </style>
    

    What needs customization is the parent of the MyTheme.Dialog this Theme.AppCompat.Light.Dialog does not work properly for all android versions it may work for Lollipop but does not work for KitKat, or the opposite.

    • With a simple run of the app in each platform you can easily find out in which version it works.
    • Then you can create a different folder for values-v21 and define the parent of the dialog accordingly, so that it work for both versions.

    You can apply some other workarounds regarding the customization of the style, in order for this to work.

    If you would like further research, or theme customization ideas take a look at the source of android theme.xml here.