- 日期选择回调函数
void calendar_event_handler(lv_obj_t* obj, lv_event_t event) { if (event == LV_EVENT_CLICKED) { lv_calendar_date_t* date = lv_calendar_get_pressed_date(obj); if (date) { lv_calendar_set_today_date(obj, date); } } }
- 日历实现
void lv_ex_calendar_1(void) { lv_obj_t* calendar = lv_calendar_create(lv_scr_act(), NULL); lv_obj_set_size(calendar, 230, 230); lv_obj_align(calendar, NULL,LV_ALIGN_CENTER, 0, 0); lv_obj_set_event_cb(calendar, calendar_event_handler); /*Set the today*/ lv_calendar_date_t today; today.year = 2020; today.month = 2; today.day = 18; lv_calendar_set_today_date(calendar, &today); lv_calendar_set_showed_date(calendar, &today); /*Highlight some days*/ static lv_calendar_date_t highlight_days[3]; highlight_days[0].year = 2020; highlight_days[0].month = 2; highlight_days[0].day = 6; highlight_days[1].year = 2020; highlight_days[1].month = 2; highlight_days[1].day = 15; highlight_days[2].year = 2020; highlight_days[2].month = 2; highlight_days[2].day = 26; lv_calendar_set_highlighted_dates(calendar, &highlight_days,3); }
- call the lv_ex_calendar_1 function in main,compile and run this exmple.