如何在Android中更改日期选择器的背景颜色

5
我需要更改安卓中calendarDatePicker的白色背景。我已经尝试了Stack Overflow上的很多链接,但都没有起作用。所以如果你有任何想法,请与我分享。我知道这是一个重复的问题,但我的要求完全不同,这就是我在这里发布问题的原因。需要将浅灰色更改为任意颜色。 这是我的日历活动
    public void calenderPicker() {
    Calendar date = Calendar.getInstance();
    CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog.newInstance(Personal.this, date.get(Calendar.YEAR), date.get(Calendar.MONTH),
                               date.get(Calendar.DAY_OF_MONTH));
    calendarDatePickerDialog.show(getFragmentManager(), FRAG_TAG_DATE_PICKER);
    }

这是我的 onDateset() 函数

@Override
    public void onDateSet(CalendarDatePickerDialog calendarDatePickerDialog, int year, int monthOfYear, int dayOfMonth) {
}

enter image description here


1
你在使用库来创建这个日期时间选择器吗? - cozeJ4
如果您正在使用com.android.datetimepicker,您可以更改库的布局中的颜色。 - cozeJ4
@Raghunandan,我不理解你想说什么。 - Anitha
1
@AnitaShalu 我使用了类似于你发布的图片的 https://github.com/flavienlaurent/datetimepicker 这个库。在资源布局部分的 date_picker_selected_date.xml 中,你可以更改背景。我没有使用你所用的同一个库。 - Raghunandan
1
或者您可以前往 https://android.googlesource.com/platform/frameworks/opt/datetimepicker/+/master,下载源代码(tgz),将其作为模块库导入到您的项目中,然后在 XML 文件中自定义对话框以满足您的需求。 - cozeJ4
显示剩余12条评论
1个回答

4
用户Raghunandhan在评论中准确指出了您需要更改背景颜色的位置。
正如他告诉你要查看这个github帖子。此外,您可以在项目中实现这一点。
datetimepicker-library/res/layout/date_picker_selected_date.xml:中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/day_picker_selected_date_layout"
    android:layout_width="@dimen/date_picker_component_width"
    android:layout_height="0.0dip"
    android:layout_weight="1.0"
    android:background="#C689F5"   //change the background color for your requirement
    android:gravity="center"
    android:orientation="vertical">

.........
.........
</LinearLayout>

输出:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接