How do you set the colour of a set of dropdown items>

Description

I would like to set the colour of the items in a dropdown

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

Simulator

What LVGL version are you using?

8.1

What do you want to achieve?

I would like to set the colour of the items in a dropdown

What have you tried so far?

A number of things includding

  lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN | LV_PART_ITEMS);
  lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_ITEMS);

Screenshot and/or video

Thanks!

@embeddedt / @kisvegabor any ideas?

Thanks in anticipation.
Alex

It needs to be set on the dropdown’s list, not the dropdown itself.

lv_obj_set_style_bg_color(lv_dropdown_get_list(roller_temp), lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);

Hmm, when I add that line here:

  lv_dropdown_set_options(roller_temp,
                      "7.00\n"
                      "19.00\n"
                      "19.50\n"
                      "20.00\n"
                      "20.50\n"
                      "21.00\n"
                      "21.50\n"
                      "22.00\n"
                      "22.50\n"
                      "23.00\n"
                      "23.50\n"
                      "24.00\n"
  );
  lv_obj_set_style_bg_color(roller_temp, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
  lv_obj_set_style_bg_color(lv_dropdown_get_list(roller_temp), lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
  lv_obj_set_style_border_color(roller_temp, MAIN_BORDER_COLOUR, LV_PART_MAIN);

I get the following:

Any ideas what I’m doing wrong?

I also tried this:

  lv_dropdown_set_options(roller_temp,
                      "7.00\n"
                      "19.00\n"
                      "19.50\n"
                      "20.00\n"
                      "20.50\n"
                      "21.00\n"
                      "21.50\n"
                      "22.00\n"
                      "22.50\n"
                      "23.00\n"
                      "23.50\n"
                      "24.00\n"
  );
  lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
	static lv_style_t style_list;
	lv_style_init(&style_list);
	lv_style_set_bg_color(&style_list, lv_color_hex(MAIN_BG_COLOUR));
	lv_obj_add_style(list, &style_list, LV_PART_MAIN); 

But get the same segfault :frowning:

Strange. I tested it on the MicroPython simulator (which should behave identically to C) and it worked there. list isn’t NULL by chance, is it?

Yes, looks like its NULL…

If I add the following it doesnt crash but doesnt style the list:

  lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
	static lv_style_t style_list;
	lv_style_init(&style_list);
	lv_style_set_bg_color(&style_list, lv_color_hex(MAIN_BG_COLOUR));
	if (NULL != list)
  {
    lv_obj_add_style(list, &style_list, LV_PART_MAIN); 
  }

I wonder whats wrong?

Prior to v8.2 it was only created when you open the list, that’s why it’s NULL. The change was made at the end of November, about 2 weeks after v8.1 was released.

(The MicroPython simulator is built against a relatively recent master snapshot.)

Ah!!!
Well, that would explain it!

So… Either update to 8.2 or add it to a callback when what LV_EVENT_VALUE_CHANGED?

Fount it (Dropdown list change font - #2 by Titkov_AV):
LV_EVENT_READY

  lv_obj_add_event_cb(roller_temp, heating_ddl_cb_ready, LV_EVENT_READY, NULL);
void heating_ddl_cb_ready(lv_event_t * event)
{
  lv_obj_t * list = lv_dropdown_get_list(roller_temp); /*Get the list*/
  lv_obj_set_style_bg_color(list, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);

}

Thanks @embeddedt !!