Last year, I have published the CustomCalendarView Open Source Android library. This library makes it easy to add an Calendar to your Android application.

Since then many people are asking questions like how to use Decorators and how to disable some dates in CustomCalendarView. This post answers that.

In this example, we will disable all the dates that are past.


public class CalendarDayDecoratorActivity extends AppCompatActivity {
    private CustomCalendarView calendarView;
    private TextView selectedDateTv;

    protected void onCreate(Bundle savedInstanceState) {
        selectedDateTv = (TextView) findViewById(;

        Toolbar toolbar = (Toolbar) findViewById(;

        //Initialize CustomCalendarView from layout
        calendarView = (CustomCalendarView) findViewById(;

        //Initialize calendar with date
        Calendar currentCalendar = Calendar.getInstance(Locale.getDefault());

        //Show monday as first date of week

        //Show/hide overflow days of a month

        //call refreshCalendar to update calendar the view

        //Handling custom calendar events
        calendarView.setCalendarListener(new CalendarListener() {
            public void onDateSelected(Date date) {
                if (!CalendarUtils.isPastDay(date)) {
                    SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
                    selectedDateTv.setText("Selected date is " + df.format(date));
                } else {
                    selectedDateTv.setText("Selected date is disabled!");

            public void onMonthChanged(Date date) {
                SimpleDateFormat df = new SimpleDateFormat("MM-yyyy");
                Toast.makeText(CalendarDayDecoratorActivity.this, df.format(date), Toast.LENGTH_SHORT).show();

        //adding calendar day decorators
        List<DayDecorator> decorators = new ArrayList<>();
        decorators.add(new DisabledColorDecorator());

    public boolean onOptionsItemSelected(MenuItem item) {
        // handle arrow click here
        if (item.getItemId() == {
            finish(); // close this activity and return to preview activity (if there is any)
        return super.onOptionsItemSelected(item);

    private class DisabledColorDecorator implements DayDecorator {
        public void decorate(DayView dayView) {
            if (CalendarUtils.isPastDay(dayView.getDate())) {
                int color = Color.parseColor("#a9afb9");


Join The Discussion

Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.
  • రామకృష్ణ శర్మ

    Hi i am not able to give current day background color can u please give code snippet, And each every day background color code i need to change can u help me

  • salem

    thank you for this article and your description

  • JWest

    How could I get the current selected date of the calendar in a Button event? I have a button below of the calendar. After the user click into calendar, He needs to click a button to go to next activity. I need to get the selected date clicked to pass as a bunlde. Is it possible? I have used Date dd=calendarView.getCurrentCalendar().getTime(); but it returns the current date not the selected date.