UIBinder: load background images in the bundle

It took me a while to figure this out, but finally I found a solution to load CSS background images for styles defined in a *.ui.xml:

  1. Copy the image to the same package as your *.ui.xml
  2. In the ui.xml add a “ui:data” tag that points to the image
  3. In the style block add an @url line that points to the ui:data field
  4. Use it in the style

<ui:data field=’logoImg’ src=’feederator.png’/>

<style>

@url logoUrl logoImg; 
.logo {
background: logoUrl no-repeat 0 0;
height: 55px;
    width: 250px;
}
</style>
Posted by Daniel Eichhorn

Daniel Eichhorn is a software engineer and an enthusiastic maker. He loves working on projects related to the Internet of Things, electronics, and embedded software. He owns two 3D printers: a Creality Ender 3 V2 and an Elegoo Mars 3. In 2018, he co-founded ThingPulse along with Marcel Stör. Together, they develop IoT hardware and distribute it to various locations around the world.

Leave a Reply