How to set background colour of slider?

Description

I have some sliders that I want to set the background colour. For the life of me I cant find out whats going wrong. The colour that I set isnt the one that ends up on screen…

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

Simulator

What LVGL version are you using?

8.1

What do you want to achieve?

Set the slider main to the value I want…

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

	lv_obj_t * sliderName = lv_slider_create(parent);
	//lv_obj_remove_style_all(sliderName);
	//lv_obj_set_width(blslider, screenWidth-100);              /*Set the width*/
    lv_obj_set_pos(sliderName, xpos, yPos);
	lv_obj_set_height(sliderName, 25);                          /*Set height*/
	lv_obj_set_width(sliderName, sliderWidth);
    lv_obj_set_style_bg_color(sliderName, lv_color_hex(0x01a2b1), LV_PART_INDICATOR);

	lv_obj_set_style_opa(sliderName, LV_OPA_100, LV_PART_MAIN);
    lv_obj_set_style_bg_color(sliderName, lv_color_hex(0x000000), LV_PART_MAIN);

	static lv_style_t style_slider;
	lv_style_init(&style_slider);
	lv_style_set_bg_color(&style_slider, lv_color_hex(0x58585E));
	lv_obj_add_style(sliderName, &style_slider, LV_PART_KNOB); 

Screenshot and/or video

image

This clearly isnt 0x000000…

Thanks!

@embeddedt, any ideas/suggestions?

Thanks in advance
Alex

@kisvegabor , any ideas/suggestions?

Many thanks
Alex

Have you checked this document?

Slider (lv_slider) — LVGL documentation

Yes.

The problem is that the colour I specify isnt the one thats applied.

Can you try to define the colour as such

lv_color_t YourColorInHSV = lv_color_hsv_to_rgb(190, 88, 52); //0x01a2b1
 lv_color_t black= lv_color_hsv_to_rgb(0, 0, 0); //0x000000

and then define the bg colour like this:

    lv_obj_set_style_bg_color(sliderName,YourColorInHSV , LV_PART_INDICATOR);
    lv_obj_set_style_bg_color(sliderName, black, LV_PART_MAIN);

No change :frowning:

This is very odd… Its like it just doesnt want to apply the style to the slider…

But it is doing something. When I remove the style I get this:

Use:

lv_obj_set_style_bg_opa(sliderName, LV_OPA_100, LV_PART_MAIN);

But not:

lv_obj_set_style_opa(sliderName, LV_OPA_100, LV_PART_MAIN);

image

Amazing!! You rock!

Thank you so very much for this. Really appreciated.

Thanks for your reply, i will try this.