Material-calendarview: Change color of past dates only

Created on 8 May 2019  路  3Comments  路  Source: prolificinteractive/material-calendarview

Is there a way to set different color to past dates ?

Most helpful comment

You need to create a _DayViewDecorator_ like the code below(replace the R.color.grey with a color you want):

`class PastDaysDecorator(private val context: Context) : DayViewDecorator {

override fun shouldDecorate(day: CalendarDay): Boolean {
    return day.isBefore(CalendarDay.today())
}

override fun decorate(view: DayViewFacade) {
    view.addSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.grey)))
}

}`

All 3 comments

Use a decorator

You need to create a _DayViewDecorator_ like the code below(replace the R.color.grey with a color you want):

`class PastDaysDecorator(private val context: Context) : DayViewDecorator {

override fun shouldDecorate(day: CalendarDay): Boolean {
    return day.isBefore(CalendarDay.today())
}

override fun decorate(view: DayViewFacade) {
    view.addSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.grey)))
}

}`

You need to create a _DayViewDecorator_ like the code below(replace the R.color.grey with a color you want):

`class PastDaysDecorator(private val context: Context) : DayViewDecorator {

override fun shouldDecorate(day: CalendarDay): Boolean {
    return day.isBefore(CalendarDay.today())
}

override fun decorate(view: DayViewFacade) {
    view.addSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.grey)))
}

}`

Thanks!!! you rock

Was this page helpful?
0 / 5 - 0 ratings