Style DatePickerDialog selector background

292 Views Asked by At

Does anyone know how to style the black boxes surrounding the date selectors so that they match the background of my DatePickerDialog? Broken DatePickerDialog

For reference here is the style I'm using for AlertDialogs:

<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:colorBackground">@android:color/white</item>
    <item name="colorAccent">@color/group_blue_800</item>
    <item name="android:textColorPrimary">@color/secondary_text</item>
    <item name="android:textColor">@color/primary_text</item>
    <item name="android:lineSpacingMultiplier">1.2</item>
    <item name="colorControlNormal">@android:color/white</item>
    <item name="colorPrimary">@android:color/white</item>
    <item name="colorPrimaryDark">@android:color/white</item>
</style>
1

There are 1 best solutions below

0
On BEST ANSWER

I resolved this by creating a standalone style for DatePickers/TimePickers for pre-Lollipop devices:

<style name="PreLollipopDatePickerStyle" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:lineSpacingMultiplier">1.2</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:colorBackground">@android:color/white</item>
        <item name="android:textColorPrimary">@color/secondary_text</item>
        <item name="android:textColorSecondary">@color/secondary_text</item>
        <item name="android:textColor">@color/primary_color</item>
        <item name="colorAccent">@color/group_blue_800</item>
    </style>

I then create a DatePicker/TimePicker using the constructor where you pass a theme resource ID for pre-Lollipop devices:

DatePickerDialog datePickerDialog;
if (AndroidUtils.isLollipop()) {
    datePickerDialog = new DatePickerDialog(
        getActivity(),
        new EndDateTimeSelectedListener(),
        endDateTimeExclusive.get(Calendar.YEAR),
        endDateTimeExclusive.get(Calendar.MONTH),
        endDateTimeExclusive.get(Calendar.DAY_OF_MONTH));
} else {
    datePickerDialog = new DatePickerDialog(
        getActivity(),
        R.style.PreLollipopDatePickerStyle,
        new EndDateTimeSelectedListener(),
        endDateTimeExclusive.get(Calendar.YEAR),
        endDateTimeExclusive.get(Calendar.MONTH),
        endDateTimeExclusive.get(Calendar.DAY_OF_MONTH));
}

datePickerDialog.show();