Convert Figma logo to code with AI

prolificinteractive logomaterial-calendarview

A Material design back port of Android's CalendarView

5,916
1,318
5,916
252

Top Related Projects

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

An android library which provides a compact calendar view much like the one used in google calenders.

A better calendar for Android

Standalone Android widget for picking a single date from a calendar view.

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Quick Overview

Material CalendarView is an Android library that provides a customizable calendar widget following Material Design principles. It offers a clean, modern interface for displaying and interacting with dates, making it ideal for apps that require date selection or event scheduling functionality.

Pros

  • Follows Material Design guidelines for a polished, modern look
  • Highly customizable with various styling options and themes
  • Supports both single date and date range selection
  • Integrates well with other Android components and libraries

Cons

  • Limited to Android platform only
  • May require additional setup for more complex use cases
  • Documentation could be more comprehensive
  • Some advanced features may require deeper understanding of the library's internals

Code Examples

  1. Basic calendar setup:
val calendarView = findViewById<MaterialCalendarView>(R.id.calendarView)
calendarView.selectionMode = MaterialCalendarView.SELECTION_MODE_SINGLE
calendarView.setOnDateChangedListener { widget, date, selected ->
    // Handle date selection
}
  1. Customizing calendar appearance:
calendarView.setTitleAnimationOrientation(MaterialCalendarView.VERTICAL)
calendarView.setTitleMonths(R.array.custom_months)
calendarView.setWeekDayLabels(R.array.custom_weekdays)
calendarView.setDateTextAppearance(R.style.CustomDateTextAppearance)
  1. Adding decorators for specific dates:
val eventDecorator = EventDecorator(Color.RED, listOf(CalendarDay.today()))
calendarView.addDecorator(eventDecorator)

class EventDecorator(private val color: Int, private val dates: Collection<CalendarDay>) : DayViewDecorator {
    override fun shouldDecorate(day: CalendarDay): Boolean = dates.contains(day)
    override fun decorate(view: DayViewFacade) {
        view.addSpan(DotSpan(5f, color))
    }
}

Getting Started

  1. Add the dependency to your app's build.gradle:
dependencies {
    implementation 'com.github.prolificinteractive:material-calendarview:2.0.1'
}
  1. Add the MaterialCalendarView to your layout XML:
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  1. Initialize and customize the calendar in your Activity or Fragment:
val calendarView = findViewById<MaterialCalendarView>(R.id.calendarView)
calendarView.selectionMode = MaterialCalendarView.SELECTION_MODE_SINGLE
calendarView.setOnDateChangedListener { widget, date, selected ->
    // Handle date selection
}

Competitor Comparisons

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

Pros of Calendar

  • More customizable and flexible, allowing for complex calendar layouts
  • Better performance, especially for large date ranges
  • Supports both vertical and horizontal scrolling

Cons of Calendar

  • Steeper learning curve due to increased complexity
  • Less out-of-the-box Material Design styling

Code Comparison

Material-CalendarView:

calendarView.setOnDateChangedListener { widget, date, selected ->
    // Handle date selection
}

Calendar:

class DayViewContainer(view: View) : ViewContainer(view) {
    val textView = view.findViewById<TextView>(R.id.calendarDayText)
    // Bind data to the container
}

calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

The Calendar library requires more setup but offers greater flexibility in customizing day views and interactions. Material-CalendarView provides a simpler API for basic calendar functionality but may be less adaptable for complex use cases.

An android library which provides a compact calendar view much like the one used in google calenders.

Pros of CompactCalendarView

  • More compact design, suitable for smaller screen spaces
  • Simpler API with fewer customization options, making it easier to implement quickly
  • Lightweight with minimal dependencies

Cons of CompactCalendarView

  • Less extensive customization options compared to Material-CalendarView
  • Fewer built-in features and event handling capabilities
  • Less active development and community support

Code Comparison

CompactCalendarView:

CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendarView.setUseThreeLetterAbbreviation(true);
compactCalendarView.setFirstDayOfWeek(Calendar.MONDAY);
compactCalendarView.setIsRtl(false);
compactCalendarView.displayOtherMonthDays(false);

Material-CalendarView:

MaterialCalendarView materialCalendarView = (MaterialCalendarView) findViewById(R.id.calendarView);
materialCalendarView.setSelectionColor(Color.BLUE);
materialCalendarView.setWeekDayTextAppearance(R.style.CustomTextAppearance);
materialCalendarView.setHeaderTextAppearance(R.style.CustomHeaderTextAppearance);
materialCalendarView.setDateSelected(CalendarDay.today(), true);

Both libraries offer easy-to-use calendar views for Android applications. CompactCalendarView focuses on simplicity and compact design, while Material-CalendarView provides more extensive customization options and follows Material Design principles. The choice between the two depends on the specific requirements of your project, such as screen space constraints, desired customization level, and adherence to design guidelines.

A better calendar for Android

Pros of Caldroid

  • More customizable appearance with support for custom cell views
  • Easier to implement custom date selection logic
  • Supports both vertical and horizontal swiping for month navigation

Cons of Caldroid

  • Less Material Design-oriented UI compared to Material-CalendarView
  • May require more setup code for basic functionality
  • Documentation is not as comprehensive

Code Comparison

Material-CalendarView:

MaterialCalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setOnDateSelectedListener(new OnDateSelectedListener() {
    @Override
    public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
        // Handle date selection
    }
});

Caldroid:

CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
args.putInt(CaldroidFragment.MONTH, month);
args.putInt(CaldroidFragment.YEAR, year);
caldroidFragment.setArguments(args);

FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar_container, caldroidFragment);
t.commit();

Both libraries offer calendar functionality for Android applications, but Material-CalendarView focuses more on Material Design principles, while Caldroid provides greater customization options. The choice between them depends on specific project requirements and design preferences.

Standalone Android widget for picking a single date from a calendar view.

Pros of android-times-square

  • Lightweight and simple implementation
  • Easy to customize with custom date decorators
  • Supports both single date and date range selection

Cons of android-times-square

  • Less modern UI design compared to Material Design guidelines
  • Limited built-in styling options
  • Lacks some advanced features like event markers

Code Comparison

material-calendarview:

CalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_MULTIPLE);
calendarView.addDecorator(new EventDecorator(Color.RED, dates));

android-times-square:

CalendarPickerView calendar = findViewById(R.id.calendar_view);
calendar.init(startDate, endDate)
    .inMode(CalendarPickerView.SelectionMode.MULTIPLE)
    .withSelectedDates(selectedDates);

Both libraries offer similar basic functionality for calendar views in Android applications. material-calendarview provides a more modern Material Design-inspired look and feel, with additional features like event markers and more customization options. android-times-square, on the other hand, offers a simpler and more lightweight implementation that may be easier to integrate and customize for specific needs. The choice between the two depends on the project requirements, desired aesthetics, and the level of customization needed.

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Pros of Android-Week-View

  • Offers a week view layout, which is not available in Material-CalendarView
  • Provides more customization options for event display and time slots
  • Supports horizontal scrolling for navigating between weeks

Cons of Android-Week-View

  • Less focus on material design principles compared to Material-CalendarView
  • May require more setup and configuration for basic usage
  • Limited built-in theming options

Code Comparison

Material-CalendarView:

CalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setOnDateChangedListener(new OnDateSelectedListener() {
    @Override
    public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
        // Handle date selection
    }
});

Android-Week-View:

WeekView weekView = findViewById(R.id.weekView);
weekView.setOnEventClickListener(new WeekView.EventClickListener() {
    @Override
    public void onEventClick(WeekViewEvent event, RectF eventRect) {
        // Handle event click
    }
});

Both libraries offer easy-to-use calendar implementations, but Android-Week-View focuses on a week-based layout with more detailed event handling, while Material-CalendarView provides a traditional month view with material design aesthetics. The choice between them depends on the specific calendar layout and functionality required for your application.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Material Calendar View

Android Arsenal Travis branch

A Material design back port of Android's CalendarView. The goal is to have a Material look and feel, rather than 100% parity with the platform's implementation.

Demo Screen Capture

Installation

Step 1. Add the JitPack repository to your build file

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2. Add the dependency

dependencies {
  implementation 'com.github.prolificinteractive:material-calendarview:${version}'
}

Usage

  1. Add MaterialCalendarView into your layouts or view hierarchy.
  2. Set a OnDateSelectedListener or call MaterialCalendarView.getSelectedDates() when you need it.

Javadoc Available Here

Example:

<com.prolificinteractive.materialcalendarview.MaterialCalendarView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:mcv_showOtherDates="all"
    app:mcv_selectionColor="#00F"
    />

Documentation

Make sure to check all the documentation available here.

Customization

One of the aims of this library is to be customizable. The many options include:

Events, Highlighting, Custom Selectors, and More!

All of this and more can be done via the decorator api. Please check out the decorator documentation.

Recent Changes

Major Change in 2.0

Material CalendarView 2.0 comes in with a major change into the core of it's API, we transitioned from using java.util.Calendar to java.time.LocalDate. Also that should not impact the public api (we are still using CalendarDay), both Calendar and LocalDate function a little bit differently. One example of that: Months are now indexed from 1 (January) to 12 (December). You can access from the LocalDate from CalendarDay using getDate().

Major Change in 1.6.0

Also this release doesn't have any break changes, it provides significant improvements to the widget. More customization have been added for the user (custom fonts, long click listener, show/hide weekdays) as well as various fixes, improvements to the sample app, and general cleanup. Make sure to check the CHANGELOG and the release section for more details.

Major Change in 1.5.0

We recently updated to the latest gradle and decided to move over our libraries to the hosting service Jitpack. Please refer to the installation section for more details.

Major Change in 1.4.0

  • Breaking Change: setFirstDayOfWeek, setMin/MaxDate, and setCalendarDisplayMode are moved to a State object. This was necessary because it was unclear that these were not simple setters--individually, they were side effecting and triggered full adapter/date range recalculations. Typical usage of the view involves setting all these invariants up front during onCreate and it was unknown to the user that setting all 4 of these would create a lot of waste. Not to mention certain things were side effecting--some would reset the current day or selected date. As a result, the same 4 methods called in a different order could result in a different state, which is bad.

    For most cases you will simply need to replace setting those invariants with:

    mcv.state().edit()
      .setFirstDayOfWeek(Calendar.WEDNESDAY)
      .setMinimumDate(CalendarDay.from(2016, 4, 3))
      .setMaximumDate(CalendarDay.from(2016, 5, 12))
      .setCalendarDisplayMode(CalendarMode.WEEKS)
      .commit();
    

    mcv.state().edit() will retain previously set values; mcv.newState() will create a new state using default values. Calling commit will trigger the rebuild of adapters and date ranges. It is recommended these state changes occur as the first modification to MCV (before configuring anything else like current date or selected date); we make no guarantee those modifications will be retained when the state is modified.

    See CUSTOMIZATION_BUILDER for usage details.

  • New: setSelectionMode(SELECTION_MODE_RANGE) was added to allow 2 dates to be selected and have the entire range of dates selected. Much thanks to papageorgiouk for his work on this feature.

See other changes in the CHANGELOG.

Contributing

Would you like to contribute? Fork us and send a pull request! Be sure to checkout our issues first.

License

Material Calendar View is Copyright (c) 2018 Prolific Interactive. It may be redistributed under the terms specified in the LICENSE file.

Maintainers

prolific

Material Calendar View is maintained and funded by Prolific Interactive. The names and logos are trademarks of Prolific Interactive.