我正在尝试实现一个日历,其中一周的第一天和一周的最后几天的颜色会有所不同。现在我可以为今天、 Activity 日和正常日子着色,但是,我在如何比较“日”是否是一周的第一天时遇到了困难。
我有这个功能:
/**
* This method is used to set a color of texts, font types and backgrounds of TextView objects
* in a current visible month. Visible day labels from previous and forward months are set using
* setDayColors() method. It also checks if a day number is a day number of today and set it
* a different color and bold face type.
*
* @param day A calendar instance representing day date
* @param today A calendar instance representing today date
* @param dayLabel TextView containing a day numberx
* @param calendarProperties A resource of a color used to mark today day
*/
public static void setCurrentMonthDayColors(Calendar day, Calendar today, TextView dayLabel,
CalendarProperties calendarProperties) {
Log.i(TAG,"Day: " + day);
if (today.equals(day)) {
setDayColors(dayLabel, calendarProperties.getTodayLabelColor(), Typeface.BOLD,
R.drawable.background_transparent);
} else if (EventDayUtils.isEventDayWithLabelColor(day, calendarProperties)) {
EventDayUtils.getEventDayWithLabelColor(day, calendarProperties).executeIfPresent(eventDay ->
DayColorsUtils.setDayColors(dayLabel, eventDay.getLabelColor(),
Typeface.NORMAL, R.drawable.background_transparent));
} else if (calendarProperties.getHighlightedDays().contains(day)) {
setDayColors(dayLabel, calendarProperties.getHighlightedDaysLabelsColor(),
Typeface.NORMAL, R.drawable.background_transparent);
} else if (day.equals(GregorianCalendar.getInstance().getFirstDayOfWeek())) {
setDayColors(dayLabel, Color.WHITE, Typeface.BOLD,
R.drawable.background_transparent);
} else {
setDayColors(dayLabel, calendarProperties.getDaysLabelsColor(), Typeface.BOLD,
R.drawable.background_transparent);
}
}
现在在这个 else if 中:
else if (day.equals(GregorianCalendar.getInstance().getFirstDayOfWeek())) {
setDayColors(dayLabel, Color.WHITE, Typeface.BOLD,
R.drawable.background_transparent);
我试图比较我们现在设置的日期是否是一周的第一天,但是,每次我尝试比较时,我都会发现您可以将日历对象与 int 进行比较。从日志中,我可以看出“day”对象有一个字段,说明它是一周中的哪一天:
DAY_OF_WEEK=1
如果将其设置为白色,则应该根据想法检查该值是否是第一天。
最佳答案
解决了这个:
else if (day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
setDayColors(dayLabel, Color.WHITE, Typeface.NORMAL,
R.drawable.background_transparent);
关于java - 如何将一周的第一天和一周的最后一天设置为白色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57112096/