How to set some lv_menu item's color

What LVGL version are you using?


What do you want to achieve?

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

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


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


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);


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

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.

1 Like