Tabview, tab buttons change the sytle for focus?


How do you change the focus style for the button matrix of a tabview?

What MCU/Processor/Board and compiler are you using?

What LVGL version are you using?


What do you want to achieve?

change the color of the focused button when the tab is selected.

What have you tried so far?

I have tried the code below and the button pressed state color changes so I think coding is right. But the focused state color does not change.
What am I missing?


Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

  static lv_style_t style8;

  lv_style_set_bg_color(&style8, LV_STATE_FOCUSED, LV_COLOR_GREEN);  // FOCUSED is not working ???
  lv_style_set_bg_color(&style8, LV_STATE_PRESSED, LV_COLOR_RED);

  lv_obj_add_style(tabview, LV_TABVIEW_PART_TAB_BTN, &style8);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

I looked through lv_tabview_set_act. It looks like the tabview uses the “checked” feature of the button matrix on selected tabs, so I think you’re looking for LV_STATE_CHECKED, not LV_STATE_FOCUSED. I’ve submitted a pull request to add this to the docs here.

Hello, thanks for the quick response. But I have tried the LV_STATE_CHECKED and it does not work either. I still only get the red pressed state.

Also I added a default state below and that is not working either.

lv_style_set_bg_color(&style8, LV_STATE_DEFAULT, LV_COLOR_CYAN); // DEFAULT is not working ???

I have also tried adding this style to the tab and the tabview with no luck. But the border width is working and border color. when added to the tabview LV_TABVIEW_PART_TAB_BTN.
Any other suggestions?


Do you think this is a bug?

I have tried a lot of things now. It all works if I just create a BTNMATRIX. I can get the checked state to display the correct color. it just will not work in the Tabview. I have even tried to run the same code that worked on the BTNMATRIX by setting it directly on the tabview’s btnmatrix, with ext->btns, but that does not work either.

I have also checked that the btmmatrix button 0 is in the checked state.

What is different about the btmmatrix in the tabview?


Also I’m running lv_arduino which has V7.0.2 and I noticed the current version is 7.3 could this be the issue? if so when will lv_arduino be updated?


The coloring issue
It happens because the bg_opa of the tab buttons is transparent by default (except in the pressed state). So just add this line:

    lv_style_set_bg_opa(&style8, LV_STATE_CHECKED, LV_OPA_COVER);

From now you can use lvgl directly as an Arduino library.

Thank you very much! It works again.

1 Like

You are welcome!