Toggle button resets to default color when not focusssed

Description

I have a button which I set as a toggle:
lv_obj_add_flag(btnV1, LV_OBJ_FLAG_CHECKABLE);
I set a custom background color for when the button is checked:
lv_obj_set_style_bg_color(btnV1,lv_palette_main(ser1Color), LV_IMAGEBUTTON_STATE_CHECKED_RELEASED);

When I hit the button, it changes to the custom color.
When I touch anything else on the screen, this button reverts to the standard red for toggled button.

What am I missing here?

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

ESP32 CYD
VScode/Arduino

What LVGL version are you using?

9.1

What do you want to achieve?

Toggle button keeps the custom color also when not in focus.

What have you tried so far?

  • tried to find any documentation about all these button states, to no avail.

Code to reproduce

Screenshot and/or video

Have you referred to this example?

Button (lv_button) — LVGL documentation

This does not set a custom color, it’s just the standard red for toggled button.
My problem is the button doesn’t keep the custom color.

can you try lv_obj_set_style_bg_color(btn2, lv_color_hex(0x37CB9D), LV_PART_MAIN | LV_STATE_CHECKED);

1 Like

:+1:
Works. Thanks heaps.

  • Do you happen to know whether these 1001 button states are documented anywhere?

I’m not sure if this is what you need
Widget Basics — LVGL documentation

No, I meant the button specific states, the one I first tried to use.
But maybe it’s just better using the basig widget states, as you showed me…
Thanks a lot.