Android CalendarView for Showing Events

Karthik Andhamil picture Karthik Andhamil · May 15, 2013 · Viewed 74.5k times · Source

I want to show a calendar with events using different colors on the date similar to default Calendar application. But I don't see any such API on the default calendar view.

Can anyone please direct me on right direction how to proceed with this? Should I extend default calendar and add my own functionality? Or should I use 5x5 text boxes with PageViewer and fragments?

Answer

nas picture nas · May 15, 2013

The built in CalendarView widget doesn't expose the ability to change the color of the calendar cells in month view. See the source.

You might try the following approaches:

  1. Extend from CalendarView and implement onDraw yourself. You'll have to reimplement all the existing drawing behavior, including these 4 methods:

    protected void onDraw(Canvas canvas) {
        drawBackground(canvas);
        drawWeekNumbersAndDates(canvas);
        drawWeekSeparators(canvas);
        drawSelectedDateVerticalBars(canvas);
    }
    
  2. Implement you own CalendarView that allows customizing cells. I suggest this project as a good place to get started, since it already supports custom cells.