CleverPumpkin / CrunchyCalendar

A beautiful material calendar with endless scroll, range selection and a lot more!
MIT License
647 stars 45 forks source link

How to set a specific color background for specific dates? #33

Closed Jaar3096 closed 4 years ago

Jaar3096 commented 5 years ago

I have a REST service that returns an array of dates and an int value, depending of that value, the date will have a specific color. Example:

if the value is between 0 and 50, the color will be green. if the value is between 51 and 100 the color will be yellow.

and so on.

PD. The library is awsome, the only thing I have left to implement is this, help :(.

Thanks!

rAseri commented 5 years ago

Unfortunately there is no a simple way to set a special color for a specific date, but you can try to achieve this by implementing a custom ItemDecoration for the calendar. Let me explain what I mean.

There is a special library class AbsDateItemDecoration that has been designed for date cells decorating. Clients of the library are able to extend this class and implement some custom drawing logic for a specific date cells. You can extend this class and draw backgraund of a special color for a specific date cells.

I have added a sample that demonstrates how to change background color of some date cells. You can find it here.

Please note, that when I draw a background for a date cell I use color with alpha (254CA5FF for example). This is required because I draw background over date cell view so the color must be transparent.