List background color

How to keep the list background color for clicked item. By default, the background color will disappear after release. I want to know one selected item from list with background color. I need similar behavior of scroll property for pressed item

It’s because the list item is transparent by default. You can set lv_obj_can_set_style_bg_opa(item, 255, LV_PART_MAIN).

LVGL: v8.3
I tried like

lv_obj_t *list = lv_list_create(parent_obj);
lv_obj_t *list_btn = lv_list_add_btn(list, LV_SYMBOL_FILE, "filename");
lv_obj_set_style_bg_opa(list_btn , 255, LV_PART_MAIN);

But background color is disappear after release. I would like to hold background color for when list item clicked to know the selected item.

And also I would like to know, how to hold the background color of all clicked list items like as shown as printer demo for copy files.

Try this:

  lv_obj_t *list = lv_list_create(lv_scr_act());
  lv_obj_t *list_btn = lv_list_add_btn(list, LV_SYMBOL_FILE, "filename");
  lv_obj_set_style_bg_opa(list_btn , 255, LV_STATE_CHECKED);
  lv_obj_set_style_bg_color(list_btn , lv_color_hex3(0xf00), LV_STATE_CHECKED);
  lv_obj_set_style_transform_width(list_btn , 20, LV_STATE_CHECKED);
  lv_obj_add_flag(list_btn, LV_OBJ_FLAG_CHECKABLE);
1 Like