从日历 View 禁用星期五

2019年7月25日 21点热度 0条评论

我在我的应用中使用日历视图,我需要从中禁用“星期五”的选择,并且如果可能需要将其显示为灰色(不可选择)

<CalendarView
    android:id="@+id/simpleCalendarView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

解决方案如下:

private Calendar lastSelectedCalendar = null;
private CalendarView calendarView;


calendarView = (CalendarView) findViewById(R.id.calendarView);
lastSelectedCalendar = Calendar.getInstance();
calendarView.setMinDate(lastSelectedCalendar.getTimeInMillis() - 1000);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
    Calendar checkCalendar = Calendar.getInstance();
    checkCalendar.set(year, month, dayOfMonth);
    if(checkCalendar.equals(lastSelectedCalendar))
        return;
    if(checkCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY)
        calendarView.setDate(lastSelectedCalendar.getTimeInMillis());
    else
        lastSelectedCalendar = checkCalendar;
}
});