Layout: Label color

Former Member
Former Member
Hey guys,

Is there a way to specify layout label color dynamically via the resources or the code?

Thanks!
  • If you are trying to change the text color, you can ask the view for the drawable, and then you can change the color. For example, if your layout has a label with id="blah", you could write getDrawableById("blah").setColor(Gfx.COLOR_RED) in the view implementation to change the label color.

    Another option would be to make a custom drawable class that looks to a variable you control for its color, and then update your resource file to use the custom drawable. Something like this...

    class MyText extends Ui.Drawable
    {
    static var backgroundColor = Gfx.COLOR_BLACK;
    static var foregroundColor = Gfx.COLOR_WHITE;
    var font;
    var text;
    var justification;

    function initialize(params) {
    Drawable.initialize(params);

    font = params[:font];
    text = params[:text];
    justification = params[:justification];
    }

    function draw(dc) {
    dc.setColor(foregroundColor, backgroundColor);
    dc.drawText(locX, locY, font, text, justification);
    }
    }

    // then to change the text color of all of your text elements
    MyText.backgroundColor = Gfx.COLOR_WHITE;
    MyText.foregroundColor = Gfx.COLOR_BLACK;

    // force a redraw with the new colors
    Ui.requestUpdate();


    I'm pretty sure that should all work...

    Travis
  • Former Member
    Former Member over 9 years ago
    Oh. It was in Drawable Text subclass, missed it. Thanks bro!