white background for date picker dialog shadow

感情迁移 提交于 2019-12-05 22:34:48

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.

I had the same problem,

First Solution I have done :
I end up giving this theme in the DatePickerDialog builder. What's important is the windowBackground set to transparent.

<style name="Theme.Yp.DatePicker" parent="@android:style/Widget.DeviceDefault.DatePicker">
        <item name="android:textColor">@color/color_accent</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:gravity">center</item>
    </style>

Second and Final Solution :
I finished by using the DatePickerDialog.THEME_DEVICE_DEFAULT_LIGHT that works just fine. We didn't use a lot of styling so it was ok.

It may be late but will help.

You have to add transparent background of you dialog. Here is how you can do this:

DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog, reservationDate, 2014, 1, 1)
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }
};

for me it didn't help to set the window background to transparent, this made all my datePicker dialog with transparent not only the ugly border.. :(

what helped me is to set also the regular background to the color I wanted and the windowBackground to transparent. this is my style:

 <style name="pickerDialogDark" parent="Theme.AppCompat.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:background">?attr/dialogBackground</item>
        <item name="android:textColor">@color/colorSimpleGreen</item>
        <item name="colorAccent">@color/colorGreen</item>
        <item name="colorPrimaryDark">@color/colorBlack</item>
        <item name="android:textColorSecondary">@color/colorSimpleGreen</item>
        <item name="android:headerBackground">?attr/dialogBackground</item>
    </style>

Add a new style in the default style (not style-21)

 <style name="Your style" parent="@android:style/Widget.DeviceDefault.DatePicker">
 <item name="android:textColor">@color/app__primary_color</item>
 <item name="android:windowBackground">@android:color/transparent</item>
 <item name="android:gravity">center</item>
 <item name="android:layout_gravity">center</item>
Jeon
DatePickerDialog dialog = new DatePickerDialog(mContext, android.R.style.Theme_Holo_Light_Dialog_NoActionBar, mDateSetListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
dialog.getWindow().setBackgroundDrawableResource(R.color.transparency);
dialog.show();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!