Android:如何更改 Theme.Holo.Light.Dialog.MinWidth 中的 DatePickerDialog 颜色?

标签 android android-theme android-datepicker

我使用的是 Api 14,我发现从我的 DataPickerDialog 中隐藏日历 View 的唯一方法是在创建它时使用 Theme.Holo.Light.Dialog.MinWidth。 但现在我无法更改文本和标题的颜色。

Image of DatePickerDialog

如何更改蓝色和确定/取消按钮?

styles.xml代码

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/backtext</item>
    <!-- Customize your theme here. -->
</style>
<style name="DatePickerTheme" parent="@android:style/Theme.Holo.Light.Dialog.MinWidth">
    <item name="colorAccent">@color/border</item>
    <item name="android:headerBackground">@color/border</item>
    <item name="android:textColorHighlight">@color/backtext</item>
</style>

DatePickerDialog 创建代码:

    private void InitDatePicker() {
            Calendar newCalendar = Calendar.getInstance();
            //android.R.style.Theme_Holo_Dialog_MinWidth
            //

            datePickerDialog = new DatePickerDialog(this, R.style.DatePickerTheme,new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar newDate = Calendar.getInstance();
                    newDate.set(year, monthOfYear, dayOfMonth);
                    dtVenc.setText(new SimpleDateFormat().format(newDate.getTime()));
                }
            }, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
            HideDayButton(datePickerDialog.getDatePicker());
            datePickerDialog.setTitle("Vencimento");
}

最佳答案

试试这个

您应该使用 headerBackground 而不是 android:headerBackground 并且对于 android:textColorHighlight 删除 android 也是如此

这应该可行

关于Android:如何更改 Theme.Holo.Light.Dialog.MinWidth 中的 DatePickerDialog 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33578846/

相关文章:

android - Jetpack Compose X.dp 性能问题?

android - 如何使自定义 windowBackground 主题样式适用于所有 Android 设备?

android - 无法设置android :windowBackground Error inflation on item requires drawable child

安卓日期选择器 : Disabling the PREVIOUS dates based on the CURRENT date

android - DatePicker 导致在 LayoutEditor 中呈现期间引发异常

java - Android 上 Java 代码最重要的优化是什么?

java - 基本 REST Web 服务无法注册

android - 在 XML 可绘制对象中使用主题引用需要 API 级别 21

android - AlertDialog 的自定义主题不起作用

android - DatePickerDialog 在屏幕旋转时保存布局