Android CalendarView for Showing Events
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?
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:
-
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); }
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.
Last month I was able to implement a little calendar view using Caldroid https://github.com/roomorama/Caldroid.
It's flexible to use and it's not so hard to get a custom calendar view as implementing onDraw
from the CalendarView
.
Check the view I created (just by following the documentation):
And of course you can go beyond that.
I've written my own CalendarView much like the one seen in Google calendars aswell. Gives the ability to scroll between months, listeners, add events and is a gradle project: https://github.com/SundeepK/CompactCalendarView. It uses paint to do all the drawing so it should easy to change to do anything you want.
The following project is the best alternative I have seen so far to allow for displaying event-specific visuals in a date cell on the calendar:
https://github.com/tyczj/ExtendedCalendarView