3

enter image description here

I would like to highlight specific dates in a calendar view as in this image. is it possible to achieve it in with the default CalenderView provided by the android framework. I searched and found some libraries but I am looking for simple solution, also I dont want to creat my own calenderView. I also found that I can extend the CalenderView and add functionality to it. if so what method or parameter should I override in the extended class and how to do that.

Manohar
  • 22,116
  • 9
  • 108
  • 144
Dharmaraj
  • 174
  • 2
  • 13

1 Answers1

0

you just take custom Calender-View you just find here

And then add this extra Method in Legacy CalendarViewDelegate class similar to the setFocusedMonthDateColor() method to iterate through the weeks and set a date and color in the WeekView class

public void setMonthDateColor(Date date, int color) {                
final int childCount = mListView.getChildCount();
for (int i = 0; i < childCount; i++) {
    WeekView weekView = (WeekView) mListView.getChildAt(i);
    if (weekView.isDateInWeek(date)) {
        //this method adds the date and colour to a 
        //Map collection in weekView Object 
        weekView.setDateColour(date, color);
    }
}

}

The above method then needs to be exposed by adding another method to the parent class CalendarViewCustom (similar to its existing methods) which can then be called on an instance of the class

public int setMonthDateColor(Date date, int color) {
return mDelegate.getMonthDateColor(date, color);

}

Sarthak Dhami
  • 330
  • 1
  • 5
  • 14
  • I don't find the `LegacyCalendarViewDelegate` class inside `CalendarView` source code. also, can you elaborate your answer as I am a beginner – Dharmaraj Jul 16 '20 at 09:50