Backgroud colour

how to change the background screen color of the littlevgl screen .like i want to display the full background color of scree as BLUE,so which API i should use,can you please give me an example.?


EDIT: Updated for v8 on September 30, 2021.

Change the style of the lv_scr_act() object. You can either add a new lv_style_t object to it, or just set a local style.

I have tried this style but still getting the old them color.No changes in the background them.

static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.body.main_color = LV_COLOR_BLUE;
style.body.grad_color = LV_COLOR_BLUE;

Thanks ,

Did you call lv_obj_set_style afterwards? Did you change the style before or after you set a theme? You have to do it after, as far as I know.

1 Like


Could you please tell me how to change the theme to some color like blue or black and where to change it. Should it be in the starting of our main() program. Thanks in advance.


Are you trying to change the overall hue of the theme? When you call lv_theme_xxx_init, change the first argument to be the hue you want.

Otherwise, you would have to override the theme’s styles and change the colors in the specific areas that you want.

yes i want to change the complete theme of the display to certain color .


In that case, changing the hue parameter should work.

what is name of the file having " lv_theme_xxx_init ,"?

I don’t know. :slightly_smiling_face: It should be in your code, wherever you initialize LittlevGL and set the theme.

Do i need to change it here in ./lvgl/lv_themes/lv_theme_templ.c ?
static void basic_init(void)
lv_style_copy(&def, &lv_style_pretty); /Initialize the default style/
def.text.font = _font; = &def;
theme.panel = &def;


No; you should change it wherever you are calling the function, not where the function itself is implemented.

can you please explain it in better way of what function and where i should change it and how ?

Assuming you are already using a theme, you should have a call to lv_theme_xxx_init (where xxx is your theme of choice) in your main function, or wherever you initialize LittlevGL.

The function takes two arguments: the hue to use, and the font to use. You should pass whatever hue you want the theme to have as the first argument, and whatever font you want to use as the second argument (or NULL for the default font).

Hi this is the code for display initialization .

static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10]; /Declare a buffer for 10 lines/
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); /Initialize the display buffer/

Implement and register a function which can copy a pixel array to an area of your display:

lv_disp_drv_t disp_drv; /Descriptor of a display driver/
lv_disp_drv_init(&disp_drv); /Basic initialization/
disp_drv.flush_cb = my_disp_flush; /Set your driver function/
disp_drv.buffer = &disp_buf; /Assign the buffer to the display/
lv_disp_drv_register(&disp_drv); /Finally register the driver/

void my_disp_flush(lv_disp_t * disp, const lv_area_t * area, lv_color_t * color_p)
int32_t x, y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
set_pixel(x, y, color_p); / Put a pixel to the display.*/

lv_disp_flush_ready(disp);         /* Indicate you are ready with the flushing*/


In the display driver initialization i am getting error like “undefined reference to set_pixel”.
Can you please tell me where it is defined . ?


You need to implement the my_disp_flush function yourself; it’s what writes the pixels to your display. The code there using set_pixel is pseudocode to help you understand how the function is supposed to work.

how to put pixel on the display can you please help me .

set_pixel(x, y, color_p); / Put a pixel to the display.*/ ?


You have to have a driver for your display (this is usually platform-specific). As such, I can’t walk you through every step of that. :slightly_smiling_face:

Hi ,
I am doing the following steps in my main function for getting background but changing the hue value not getting effect and background remain black with text also light white.

lv_disp_drv_t disp_drv;
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.set_px_cb = my_set_px_cb;
disp_drv.rounder_cb = my_rounder;

    disp = lv_disp_drv_register(&disp_drv);
    lv_obj_t * scr = lv_disp_get_scr_act(NULL);
    lv_theme_t * th = lv_theme_mono_init(0, NULL);
    th = lv_theme_mono_init(210, &lv_font_roboto_22);

static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.text.color = LV_COLOR_WHITE;
style.text.font = &lv_font_roboto_22;

Kindly correct me where i am doing ?


You need to apply that style to an object for it to have an effect.