DataField backcolor

Former Member
Former Member
Hi,
I'm working on a Data Field, and I would like to use à White background with text written in back.
I just can't figure how to do this. I've tried to put <layout id="DataField" backcolor="Gfx.COLOR_WHITE">, or by code call dc.setColor with White color for foreground, but the background is still black.
Do you have any idea ?
  • DC.setcolor(Gfx.color_white, Gfx.color_black)

    It's foreground (white) and background (black). Use that variation. And try DC.clear()
  • Former Member
    Former Member over 10 years ago
    If you want to use a layout, then the only way I know is to create a rectangle in the background. eg

    <layout id="myLayout">
    <drawable id="bgFill" />
    </layout>

    <drawable-list id="bgFill" x="0" y="0" foreground="Gfx.COLOR_WHITE">
    <shape type="rectangle" width="fill" height="fill" />
    </drawable-list>


    If you opt out of using a layout, then you just set the color before calling clear

    dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
    dc.clear();
  • Former Member
    Former Member over 10 years ago
    Thanks,
    I've tried, but by backcolor is still black...:(

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
    dc.clear();
    View.onUpdate(dc);
    }
  • Former Member
    Former Member over 10 years ago
    Are you using a layout? You can't change the background color with that method if you are using a layout.
  • Former Member
    Former Member over 10 years ago
    Yeah. In my usual fashion, I registered the View.onUpdate after I had replied.
  • Thanks, I've tried, but by backcolor is still black...:(

    I think it might be helpful to explain your code so you understand what is going on. Consider your code snippet.

    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
    dc.clear();
    View.onUpdate(dc);
    }


    The first line sets the foreground color to black and the background color to white. The second color clears the entire draw area to white. This is all exactly what you want. If you comment out the third line, you can see for yourself that you'll get a white background.

    The third line renders the layout that you set in the call to setLayout() which is most likely in your onLayout() function implementation.When that layout is rendered, the first thing it does is clear the entire draw area to black. Anything that you draw before the call to View.onUpdate() will be overwritten by this.

    If you want to draw a white background when using a layout, you have to use the trick SHARKBAIT_AU showed above where the first element in the drawable list is a full screen rectangle with a white background.

    Travis
  • Former Member
    Former Member over 10 years ago
    Thanks a lot for your explanation.
    Now my Datafield is working fine.

    Pierre.