Calendar (lv_calendar)
A month calendar that highlights today and user-defined dates.
Overview
The Calendar shows the days of a month in a 7×7 grid with weekday names, highlights today, and can mark user-defined dates. The displayed month and the highlighted/selected dates are all configurable.
Learn more in the LVGL Open documentation.
/**
* @file lv_example_calendar.c
*/
#include "../lv_examples.h"
/**
* @title Calendar
* @brief A month view with today highlighted and a dropdown month picker.
*
* `shown_year`/`shown_month` choose the visible month and
* `today_year`/`today_month`/`today_day` highlight the current date. The
* `<lv_calendar-header_dropdown>` element adds dropdowns for jumping to
* another month or year.
*/
void lv_example_calendar(void)
{
static lv_style_t style_cal;
static bool inited = false;
if (!inited) {
/*Init all styles*/
lv_style_init(&style_cal);
lv_style_set_bg_color(&style_cal, lv_color_hex(0x0f172a));
lv_style_set_bg_opa(&style_cal, (255 * 100 / 100));
lv_style_set_text_color(&style_cal, lv_color_hex(0xe2e8f0));
lv_style_set_radius(&style_cal, 8);
inited = true;
}
lv_obj_t * screen = lv_screen_active();
/* 💡 Use the header dropdowns to change month or year. */
lv_obj_t * lv_calendar_0 = lv_calendar_create(screen);
lv_obj_set_size(lv_calendar_0, 260, 280);
lv_calendar_set_shown_year(lv_calendar_0, 2026);
lv_calendar_set_shown_month(lv_calendar_0, 5);
lv_obj_set_align(lv_calendar_0, LV_ALIGN_CENTER);
lv_calendar_set_today_year(lv_calendar_0, 2026);
lv_calendar_set_today_month(lv_calendar_0, 5);
lv_calendar_set_today_day(lv_calendar_0, 17);
lv_obj_add_style(lv_calendar_0, &style_cal, 0);
lv_calendar_add_header_dropdown(lv_calendar_0);
}
<!--
@title Calendar
@brief A month view with today highlighted and a dropdown month picker.
`shown_year`/`shown_month` choose the visible month and
`today_year`/`today_month`/`today_day` highlight the current date. The
`<lv_calendar-header_dropdown>` element adds dropdowns for jumping to
another month or year.
-->
<screen>
<styles>
<style name="style_cal" bg_color="0x0f172a" bg_opa="100%" text_color="0xe2e8f0" radius="8" />
</styles>
<view>
<!-- 💡 Use the header dropdowns to change month or year. -->
<lv_calendar
width="260"
height="280"
shown_year="2026"
shown_month="5"
align="center"
today_year="2026"
today_month="5"
today_day="17"
>
<style name="style_cal" />
<lv_calendar-header_dropdown />
</lv_calendar>
</view>
</screen>
Properties
Parts
Style parts of the widget with local style (e.g. style_bg_color-knob="0xff0000") or with style sheets (e.g. <style name="style_knob" selector="knob">). See Styles to learn more.
| Part | Description |
|---|---|
main | The calendar background: background and padding properties. |
items | The day cells and weekday names (built on a button matrix): background and text properties. Weekday names and days outside the shown month (disabled) are drawn without background/border. Today's thicker border and the highlighted days' fill/border are forced to the theme's primary color in code, so they are not set via style properties. |
Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.
| Property | Type | Description |
|---|---|---|
today_year | int | Mark today’s year in the calendar |
today_month | int | Mark today’s month in the calendar |
today_day | int | Mark today’s day in the calendar |
shown_year | int | Show this year in the calendar |
shown_month | int | Show this month in the calendar |
chinese_mode | bool | Show a Chinese calendar |
<lv_calendar-header_arrow>
Add arrow buttons for navigating months
access add
No attributes — created as an empty child.
<lv_calendar-header_dropdown>
Add a dropdown for selecting months or years
access add
No attributes — created as an empty child.
Last updated on