Material-calendarview: Set textcolor for all Sundays of MaterialCalendarView

Created on 21 Oct 2016  路  3Comments  路  Source: prolificinteractive/material-calendarview

I am trying to make an application for the calendar view by using MVC pattern.

com.prolificinteractive.materialcalendarview.MaterialCalendarView

I am able to change the color for all weeks,days and month , but am not able to change the color for sundays. I want to change the color to Red for those.

Is there any method to change the color for Sunday's? Can any one please give me an idea.?

Most helpful comment

Here is a quick code snippet for this

mDatePicker.addDecorator(new DayViewDecorator() {
            @Override
            public boolean shouldDecorate(CalendarDay day) {
                // check if weekday is sunday
                return day.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
            }

            @Override
            public void decorate(DayViewFacade view) {
                // add red foreground span
                view.addSpan(new ForegroundColorSpan(
                        ContextCompat.getColor(getContext(), Color.RED)));
            }
        });

All 3 comments

I'm pretty sure you could extend the Decorator class and pass your custom Decorator all the Sundays in your collection of days (might be a lot) - then the decorator knows what days are Sundays. Your Decorator would need to apply a span that colors the day red

Here is a quick code snippet for this

mDatePicker.addDecorator(new DayViewDecorator() {
            @Override
            public boolean shouldDecorate(CalendarDay day) {
                // check if weekday is sunday
                return day.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
            }

            @Override
            public void decorate(DayViewFacade view) {
                // add red foreground span
                view.addSpan(new ForegroundColorSpan(
                        ContextCompat.getColor(getContext(), Color.RED)));
            }
        });
/**
 * Highlight Saturdays and Sundays with a background
 */
public class HighlightWeekendsDecorator implements DayViewDecorator {

    private final Calendar calendar = Calendar.getInstance();
    private final Drawable highlightDrawable;
    private static final int color = Color.parseColor("#228BC34A");

    public HighlightWeekendsDecorator() {
        highlightDrawable = new ColorDrawable(color);
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        day.copyTo(calendar);
        int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
        return weekDay == Calendar.SATURDAY || weekDay == Calendar.SUNDAY;
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.setBackgroundDrawable(highlightDrawable);
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dzafiri picture dzafiri  路  3Comments

chuks picture chuks  路  6Comments

SamBob01 picture SamBob01  路  3Comments

ghost picture ghost  路  4Comments

don59 picture don59  路  3Comments