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.?
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);
}
}
Most helpful comment
Here is a quick code snippet for this