How to change the color of list's button

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

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

What LVGL version are you using?

v8.1

What do you want to achieve?

i want to change the color of the list button

What have you tried so far?

i tried lv_obj_set_style_bg_color to change, but the color is not filled the whole button, the purple is always shorter


his_data_objs[i] = lv_list_add_btn(list, NULL, “btn”);
lv_obj_set_style_bg_color(his_data_objs[i], lv_color_make(0x80, 0x80, 0xD0), LV_PART_MAIN);

GCH6EI}RGQN4O8PMX12~P}L
like this, i hope the purple is filled just like the blue

The code block(s) should be formatted like:
his_data_objs[i] = lv_list_add_btn(list, NULL, “btn”);
lv_obj_set_style_bg_color(his_data_objs[i], lv_color_make(0x80, 0x80, 0xD0), LV_PART_MAIN);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Hi

You’ll just need to adjust the bg color of the “lv_list_create” and it’s border.

Example:

lv_color_t Green= lv_color_hsv_to_rgb(148, 92, 62);//Background color

static lv_style_t btnList ;
lv_style_init(&btnList );
lv_style_set_border_color(&btnList , Green);
lv_style_set_text_color(&btnList , lv_color_white());

lv_obj_t* btnList= lv_list_create(lv_scr_act());
lv_obj_set_style_bg_color(btnList, Green, 0);
lv_obj_add_style(btnList, &btnList , LV_STATE_DEFAULT);

please let me know if it works for you.

1 Like