如何将一周的第一天和一周的最后一天设置为白色?

时间:2019-07-19 12:00:35

标签: java android calendar

我正在尝试创建一个日历,该日历的第一天和最后几天的颜色会有所不同。现在,我可以为今天,活动日和通常的日子涂色,但是,如果要比较“ Day”是否是一周的第一天,我就会陷入困境。

我有这个功能:

    /**
     * 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 (day.equals(GregorianCalendar.getInstance().getFirstDayOfWeek())) {
            setDayColors(dayLabel, Color.WHITE, Typeface.BOLD,
                    R.drawable.background_transparent);

我正在尝试比较当前设置的日期是否是一周的第一天,但​​是,每次尝试进行比较时,我都可以将日历对象与int进行比较。从日志中,我可以看出“ day”对象有一个字段,该字段指出了它在星期几:

DAY_OF_WEEK=1

通过构思,应该将该值设置为白色是否是第一天。

1 个答案:

答案 0 :(得分:0)

已解决:

 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);