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

标签 java android calendar

我正在尝试实现一个日历,其中一周的第一天和一周的最后几天的颜色会有所不同。现在我可以为今天、 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/

相关文章:

java - 如何像 JOptionPane 那样阻塞主线程?

java - 使用发布者确认设置默认超时

java - 使用它进行文件写入时如何处理 hashCode() 的负值

java - 字符串在 android 和 eclipse 控制台中显示不同

android - RxJava : Is there some sort of chain which lets me "wait until observables A, B, C are complete before continuing"?

android - 如何以编程方式创建 "Launcher" Activity ?

Android 毫秒为一次

JavaMelody - 在 GlassFish v3+ 中监控 sql 请求和 jdbc 连接

javascript - jalali 日历 for dateTimepicker jquery ui 插件

java - 如何处理 SmartGWT 日历中特定事件上的鼠标右键单击?