我想在android的calendarview中禁用周末我该怎么办? 我尝试了下面的代码,
if(DateUtils.getDayFromTS(calendarView.getDate()) == Calendar.SATURDAY ||DateUtils.getDayFromTS(calendarView.getDate()) == Calendar.SUNDAY)
calendarView.setSelected(false);
和
public static int getDayFromTS(long timestamp) {
Date date = getDateFromTimeStamp(timestamp);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_MONTH);
}
答案 0 :(得分:0)
使用setCustomizationRule
final Calendar calendar = Calendar.getInstance();
calendarView.setCustomizationRule(new Procedure<CalendarCell>() {
@Override
public void apply(CalendarCell argument) {
if (argument instanceof CalendarDayCell) {
calendar.setTimeInMillis(argument.getDate());
((CalendarDayCell) argument).setSelectable(
!(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY));
}
}
});