Tab buttons in Tabview

Each tab button in the tab view corresponds to a page, and I want to use the tab button as a normal button. For example, clicking it doesn’t switch to a page in the tab view, but listens for an event that I can use as a back button to return from the tab view to a main page.

It’s possible! E.g. in lv_example_tabview_1() add this:

static void event_cb(lv_event_t * e)
    lv_obj_t * btns = lv_event_get_current_target(e);
    lv_obj_t * tv = lv_event_get_user_data(e);
    if(lv_btnmatrix_get_selected_btn(btns) == 1) {
        lv_btnmatrix_set_btn_ctrl(btns, lv_tabview_get_tab_act(tv), LV_BTNMATRIX_CTRL_CHECKED);


lv_obj_add_event_cb(lv_tabview_get_tab_btns(tabview), event_cb, LV_EVENT_VALUE_CHANGED | LV_EVENT_PREPROCESS, tabview);

1 Like

This is really nice, this will solve a big problem for me. Thank you so much.

Hello, I just tried it, but lv_event_stop_processing(e) and LV_EVENT_PREPROCESS reported errors, do I need to include any header files? I am using lvgl v8.1.0.

It’s a v8.2 feature. Can you update lvgl?

1 Like

That’s true.
Of course.
Thank you very much for your help and confusion.

The good news is that I have implemented the function of the return button through the tab button in v8.1.0, I just removed lv_event_stop_processing(e) and LV_EVENT_PREPROCESS.
Excuse me, I also wanted to ask you a question about the tab view.
Create a Tabview, the default is the first tab button, but I want the page to be in the second tab button after the Tabview is created. How to do it?
I tried using lv_btnmatrix_set_btn_ctrl(tab_btns, 1, LV_BTNMATRIX_CTRL_CHECKED), but it didn’t work.

You can do this: lv_tabview_set_act(tv, 2, LV_ANIM_ON/OFF);

1 Like

This is ok, thank you very much, let me know the function of lv_tabview_set_act(tabview, id, LV_ANIM_ON/OFF). I need to pay attention to where this function is called.

1 Like