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");



A blogger, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He is the author of Xamarin Mobile Application Development for Android Book (, DZone MVB and founder of


Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.