样式DatePickerDialog选择器背景

时间:2017-09-13 19:23:44

标签: android datepickerdialog

有没有人知道如何设置日期选择器周围的黑框的样式,以便它们与我的DatePickerDialog的背景相匹配? Broken DatePickerDialog

此处参考的是我用于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 个答案:

答案 0 :(得分:0)

我通过为前Lollipop设备创建DatePickers / TimePickers的独立样式来解决这个问题:

<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>

然后我使用构造函数创建一个DatePicker / TimePicker,您可以在其中传递前Lollipop设备的主题资源ID:

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();