staticvoidlv_example_msgbox_1(void){staticconstchar* btns[]={"Apply","Close",""};lv_obj_t* mbox1 =lv_msgbox_create(NULL,"Hello","This is a message box with two buttons.", btns, true);lv_obj_add_event_cb(mbox1, event_cb, LV_EVENT_VALUE_CHANGED,NULL);lv_obj_center(mbox1);}
运行效果
事件处理函数中修改内容和标题
staticvoidevent_cb(lv_event_t* e){lv_obj_t* obj =lv_event_get_current_target(e);uint16_t index =lv_msgbox_get_active_btn(obj);LV_LOG_USER("Button %s clicked %d",lv_msgbox_get_active_btn_text(obj),index);if(index ==0){lv_obj_t* txt =lv_msgbox_get_text(obj);lv_label_set_text(txt,"123");}else{lv_obj_t* title =lv_msgbox_get_title(obj);lv_label_set_text(title,"456");}}