If you have a fixed number of possible hex codes, then you could add them to your stylesheet and use dynamic classes to set them on your background.
https://docs.mendix.com/refguide/common-widget-properties/#dynamicclasses
If you don't have a fixed number, then you are probably looking at having to use a JavaScript Action to manipulate the DOM to add the background.
Good luck!