Issue regarding switch indicator color in LVGL v8.0.1

Hi,

I am trying to change the indicator color of the toggle switch in the LVGL v8.0.1.
But always it is showing the default color (i.e. blue), and the color of the switch indicator is not changing as per my expectation.

Expected color code: 0x21d61e (i.e. light green).

Code Snippet for Switch:

lv_obj_t *toggle_switch = lv_switch_create(lv_scr_act());
lv_obj_set_size(toggle_switch, 70, 40);
lv_obj_align(toggle_switch, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(toggle_switch, switch_event_handler, LV_EVENT_ALL, NULL);
lv_obj_set_ext_click_area(toggle_switch, 30);
lv_obj_set_style_bg_color(toggle_switch, lv_color_hex(0x21d61e), LV_PART_INDICATOR);
if(status==1)
lv_obj_add_state(toggle_switch, LV_STATE_CHECKED);
else
lv_obj_clear_state(toggle_switch, LV_STATE_CHECKED);

Please, look into my above code implementation for a switch, and help on the same.

Kind Regards,

Amaresh

Hi,

You need to add the CHECKED state too:

  lv_obj_set_style_bg_color(toggle_switch, lv_color_hex(0x21d61e), LV_PART_INDICATOR | LV_STATE_CHECKED);
1 Like

Hi @kisvegabor,

Thanks, This is working for me.

Regards,

Amaresh