prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.92k stars 1.32k forks source link

Change color of past dates only #952

Closed dzafiri closed 5 years ago

dzafiri commented 5 years ago

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

mandricmihai commented 5 years ago

Use a decorator

munstein commented 5 years ago

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

}`

dzafiri commented 5 years ago

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