How to sustain the style of the button

Description

Good day!
When I set a style on a button, it goes back to the original when I click it.

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

M5stack、VSCode with PlatformIO、LittlevGL(v6)

What do you want to achieve?

Maintain button style after clicking.

Code to reproduce

static lv_style_t myBtn_style;
static void create_tab1(lv_obj_t * parent)
{
    obj = lv_btn_create(parent, NULL);
    lv_obj_set_event_cb(obj, btn_event_handler);

    lv_style_copy(&myBtn_style, lv_btn_get_style(obj,LV_BTN_STATE_REL));
    myBtn_style.body.main_color = LV_COLOR_RED;
    myBtn_style.body.grad_color = LV_COLOR_WHITE;
    lv_label_set_style(obj,LV_BTN_STYLE_PR,&myBtn_style); 

}

You used lv_label_set_style() to set a btn obj…

You should use lv_btn_set_style() to set the style of LV_BTN_STYLE_PR and LV_BTN_STYLE_REL

2 Likes

So this was an elementary mistake.
I am embarrassed…

Thanks for the help!