# Change screen background color from code

**URL:** <http://forum.squareline.io/t/change-screen-background-color-from-code/507>\
**Category:** How to\
**Created:** [October 16, 2022, 11:04am UTC](http://forum.squareline.io/t/change-screen-background-color-from-code/507 "2022-10-16T11:04:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [October 16, 2022, 11:04am UTC](http://forum.squareline.io/t/change-screen-background-color-from-code/507/1 "2022-10-16T11:04:58Z")

</div>

Hello,

I am trying to change a screen/display’s color from code. Initially the background is black - set from Squareline.

Reading the docs, I tried the following code without success:

```auto
lv_color_t my_color = lv_color_hex(0xFFFFFF);
lv_disp_t * d = lv_obj_get_disp(ui_SettingsScreen);
lv_disp_set_bg_color(d, my_color);

```

Any ideas why this is not working? I will keep trying.  
Thank you!

Marius

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [October 17, 2022, 8:51am UTC](http://forum.squareline.io/t/change-screen-background-color-from-code/507/2 "2022-10-17T08:51:04Z")

</div>

The background is visible only is the screen has `bg_opa != 255`.

Maybe you want to change the the screen’s background color and not the display’s. (Display is the physical display and screen is an LVGL object.)

E.g. `lv_obj_set_style_bg_color(ui_screen_1, lv_color_hex(0xffffff), 0);`

---

<div class="post-metadata">

**Author:** ![mariuselz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@mariuselz](http://forum.squareline.io/u/mariuselz)\
**Post date:** [October 17, 2022, 1:54pm UTC](http://forum.squareline.io/t/change-screen-background-color-from-code/507/3 "2022-10-17T13:54:42Z")

</div>

> [@kisvegabor](#):
>
> lv\_obj\_set\_style\_bg\_color(ui\_screen\_1, lv\_color\_hex(0xffffff), 0);

Works perfectly. Thank you so much, as always!
