How to set some lv_menu item's color

What LVGL version are you using?

v8.2

What do you want to achieve?

Change the Back button and Sidebar separator(or border?) color.
image

What have you tried so far?

 lv_obj_t *menu = lv_menu_create(lv_scr_act());

//back button
lv_obj_t *back = lv_menu_get_main_header_back_btn(menu);
lv_obj_set_style_text_color(back, lv_color_make(MY_COLOR), _LV_STYLE_STATE_CMP_SAME);  //NOT WORK

//sidebar border
lv_menu_set_sidebar_page(menu, sidebar_page);  //Set the sider menu page
lv_obj_set_style_border_color(sidebar_page, lv_color_make(MY_COLOR), _LV_STYLE_STATE_CMP_SAME);  //NOT WORK

Other Question

lv_menu_separator_create(second_page);

What is that effect,I can’t find any different after comment this line .

Hi,

I’m able to change the back button color when not using the complex menu code

lv_obj_t * menu = lv_menu_create(lv_scr_act());
lv_obj_t *back = lv_menu_get_main_header_back_btn(menu);
lv_obj_set_style_text_color(back, lv_color_make(0xff, 0x00, 0x00),_LV_STYLE_STATE_CMP_SAME);

back_button_red

But I’m unable to change it when using the complex menu code, any idea why is that @kisvegabor ?

1 Like

Just found out how to set the back button color, you should use:

lv_obj_set_style_text_color(lv_menu_get_sidebar_header_back_btn(menu), lv_color_make(0xff, 0x00, 0x00), _LV_STYLE_STATE_CMP_SAME); after lv_menu_set_sidebar_page(menu, root_page);

something like this

lv_menu_set_sidebar_page(menu, root_page);
lv_obj_set_style_text_color(lv_menu_get_sidebar_header_back_btn(menu), lv_color_make(0xff, 0x00, 0x00), _LV_STYLE_STATE_CMP_SAME);

This will set the sidebar back button to red.
imagen

1 Like