

static lv_obj_t * page1;static lv_obj_t* page2;void show_page1(void);void show_page2(void);static void event_handler(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); if(code == LV_EVENT_CLICKED) { uint8_t data = lv_event_get_user_data(e); switch (data) { case 1: lv_disp_load_scr(page2); break; case 2: lv_disp_load_scr(page1); default: break; } }}void show_page1(){ page1 = lv_obj_create(NULL); // 2. 创建显示对象 lv_obj_t* obj = lv_obj_create(page1); // 3. 给显示的对象指定样式 static lv_style_t style1; lv_style_init(&style1); lv_style_set_width(&style1, 150); lv_style_set_height(&style1, 150); lv_style_set_x(&style1, 30); lv_style_set_y(&style1, 40); lv_color_t color = lv_palette_main(LV_PALETTE_ORANGE); lv_style_set_bg_color(&style1,color); lv_style_set_radius(&style1, 20); lv_obj_add_style(obj, &style1,0); lv_obj_t* label = lv_label_create(obj); lv_label_set_text(label,"PAGE1"); lv_obj_set_align(label,LV_ALIGN_CENTER); lv_obj_add_event_cb(obj, event_handler, LV_EVENT_CLICKED, 1);}void show_page2(void){ page2 = lv_obj_create(NULL); // 2. 创建显示对象 lv_obj_t* obj = lv_obj_create(page2); // 3. 给显示的对象指定样式 static lv_style_t style1; lv_style_init(&style1); lv_style_set_width(&style1, 150); lv_style_set_height(&style1, 150); lv_style_set_x(&style1, 30); lv_style_set_y(&style1, 40); lv_color_t color = lv_palette_main(LV_PALETTE_PINK); lv_style_set_bg_color(&style1,color); lv_style_set_radius(&style1, 20); lv_obj_add_style(obj, &style1,0); lv_obj_t* label = lv_label_create(obj); lv_label_set_text(label,"PAGE2"); lv_obj_set_align(label,LV_ALIGN_CENTER); lv_obj_add_event_cb(obj, event_handler, LV_EVENT_CLICKED, 2);}