Change the state of a button

lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE); makes a button work like a toggle buttonwith a the default state blue and red when toggled. I want the default state to be red then blue when toggled.

I have tried lv_btn_set_state but this gives the error “not declared in this scope”

How can I achieve this or is there away off changing the LV_OBJ_FLAG_CHECKABLE action to swap the red and blue.

Add a style to the button:

lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_style_bg_color(btn, lv_palette_main(LV_PALETTE_GREEN), LV_STATE_CHECKED);

Excellent, thank you