Styling Individual List Elements via Flags

What do I want?

I have a fullscreen lv_list with both clickable and non-clickable elements that I am implementing with list buttons and texts. However, I want to add special styling to some of the elements – The topmost button should receiver a “header” styling, and a text element somewhere down in the list should receive a “section” style (for the sake of argument, let’s say they will receive a different background color). Another thing is I’d like to add a second text label to some of the buttons, that uses a different font, etc. pp.

I am perfectly able to style these in the application when adding the elements. But since I’m writing a custom lv_theme_t for the overall application, I’d like to do that styling in there.

So I’d like to tag these objects with some kind of flag, that then lets me change the styling applied to it.

How did I try to achieve it?

I saw that one could add user flags to any object, so when creating the elements (say the header button), I set that flag via

    item = lv_list_add_text(list, label);
    lv_obj_add_flag(item, LV_OBJ_FLAG_USER_1);

and then in my theme’s theme_apply cb (using a modified version of the default theme)

    } else if (lv_obj_check_type(obj, &lv_list_btn_class)) {
        if (lv_obj_has_flag(obj, LV_OBJ_FLAG_USER_1)) {
            lv_obj_add_style(obj, &styles->color_bg_accent, 0);

(FYI I already know that setting the color this way works).

However, this does not seem to work in that case.

Searching the forums here I found a thread with a similar idea:

but the API for the function that is exploited here has changed since (I’m on v8.3.7).

Am I using these user flags incorrectly? More generally, is there a recommended way of doing this?

Had another read of the thread above, and noticed it already has the solution for the problem I am describing. Oops.

apply_my_theme(lv_obj_t *obj) {
    theme_apply(NULL, obj);


    lv_obj_add_flag(item, LV_OBJ_FLAG_USER_1);

This can be closed then