layout.xml background color

I try to set background color in a widget via layout file.

<layout id="SunLayout" background="Gfx.COLOR_RED">
<label x="92" y="0" font="Gfx.FONT_LARGE" text="12" color="Gfx.COLOR_WHITE" />
</layout>


The text ("12") is shown properly but the background is black in the simulator.
Is this a bug or is the background no longer supported?

Thank you.
  • Thanks for the code. I managed to integrate / utilise it into my existing code (Same PM Link)

    I've did a new "DataScreen1.xml" file and changed the code in the View to reflect it.
    Did a bunch of

    View.findDrawableById( "DS1F1" ).setText(computeXXX());
    View.findDrawableById( "DS1F2" ).setText(computeYYY());


    and with this, I'm able to update the compute information into the Field Text as well a handling the changes in the MainLayout BG / FG and ACC colours.

    Nice...

    but - this could possibly be the easy part - the hard part is still ... UnReSolved. :-(
  • what's mLayout? I don't see this array being declared anywhere.

    It is an undocumented member variable of the base class Ui.View. I probably should be caching the return from setLayout in a member variable and using that, but I'm not.

    After some experimenting, seems like the array will be comprised of all the "lines" in the layout xml file????

    Yes, every element in that Lang.Array maps to a sub-element of the layout described in the xml. Every label element is turned into Ui.Text and every drawable is turned in to some undocumented type which can be drawn.

    beside size(), what are the ways to Print Out all the values in the array? (I tried toString() and values() doesn't seem to work)

    Well, the object is a Lang.Array, so you can do whatever you can do with a Lang.Array allows. You're already iterating over each element and calling toString() on each, so that is as much as you get from the array. Once you start looking at the elements in the array there isn't much you can do without knowing the dynamic type of the objects.

    MonkeyC allow you to determine the actual type of an object via instanceof, but in order for this to be useful, you need to know all of the possible types. You can write code like this to recursively walk an object displaying its values (sorry it may be a bit crude, I wrote it when tinkering with the initial version of ConnectIQ)...

    using Toybox.Lang as Lang;
    using Toybox.System as Sys;

    class DumperImpl {

    var callbacks;
    var registered;

    function initialize() {
    callbacks = new [10];
    registered = 0;

    callbacks[registered] = method(:dumpPrimitive);
    registered += 1;

    callbacks[registered] = method(:dumpString);
    registered += 1;

    callbacks[registered] = method(:dumpArray);
    registered += 1;

    callbacks[registered] = method(:dumpDictionary);
    registered += 1;
    }

    //! register a callback for dumping user-defined types
    function register(callback) {

    if (callbacks.size() == (registered - 1)) {
    var buf = new [registered + 10];

    for (var i = 0; i < registered; ++i) {
    buf= callbacks;
    }

    callbacks = buf;
    }

    callbacks[registered] = callback;
    registered += 1;
    }

    //! return a string representation of `obj'
    function dump(obj) {

    for (var i = 0; i < registered; ++i) {
    var s = callbacks.invoke(obj);
    if (s != null) {
    return s;
    }
    }

    return "?";
    }


    function dumpPrimitive(obj)
    {
    if (obj instanceof Lang.Long ||
    obj instanceof Lang.Float ||
    obj instanceof Lang.Double ||
    obj instanceof Lang.Symbol ||
    obj instanceof Lang.Number ||
    obj instanceof Lang.Boolean) {
    return obj.toString();
    }

    return null;
    }

    function dumpString(obj) {
    if (obj instanceof Lang.String) {
    var s = "'";
    s += obj.toString();
    s += "'";
    return s;
    }

    return null;
    }

    function dumpArray(obj) {

    if (obj instanceof Lang.Array) {
    if (obj.size()) {
    var r = "[ ";

    var n = obj.size() - 1;
    for (var i = 0; i < n; ++i) {
    r += dump(obj);
    r += ", ";
    }

    r += dump(obj[n]);
    r += " ]";

    return r;
    }
    else {
    return "[]";
    }
    }

    return null;
    }

    function dumpDictionary(obj) {
    if (obj instanceof Lang.Dictionary) {
    if (obj.size()) {
    var r = "{ ";

    var k = obj.keys();
    var v = obj.values();

    var n = obj.size() - 1;
    for (var i = 0; i < n; ++i) {
    r += dump(k);
    r += " => ";
    r += dump(v);
    r += ", ";
    }

    r += dump(k[n]);
    r += " => ";
    r += dump(v[n]);
    r += " }";

    return r;
    }
    else {
    return "{}";
    }
    }
    return null;
    }
    }

    module Dumper {

    var _impl;

    //! register a callback with the system
    function register(callback) {
    if (_impl == null) {
    _impl = new DumperImpl();
    }

    _impl.register(callback);
    }

    //! invoke the named callback
    function dump(obj) {
    if (_impl == null) {
    _impl = new DumperImpl();
    }

    Sys.println(_impl.dump(obj));
    }
    }
    [/code]

    If you know about a type not already described by the Dumper you can do something like this...

    class MyApp extends App.AppBase
    {
    function onStart() {
    Dumper.register(method(:dumpText));
    Dumper.register(method(:dumpBitmap));
    }

    function dumpText(obj) {
    {
    if (obj instanceof Ui.Text) {
    // you could return a string that is more descriptive
    return "Ui.Text";
    }
    return null;
    }

    function dumpBitmap(obj) {
    if (obj instanceof Ui.Bitmap) {
    return "Ui.Bitmap";
    }

    return null;
    }

    // snip
    }


    The code above basically is to check if the line in that layout file is / has UI.Text and does the changes there..

    Yes.
  • I don;t know if this is due to 1.1.4 SDK but .. look at the before vs after commenting out of using the Layout

    // On Show Free: 12934 used:52602 total:65536
    // Afer removing setLayout(Rez.Layouts.DataScreen1(dc));
    // On Show Free: 20287 used:45249 total:65536


    8kb!!
  • Former Member
    Former Member over 7 years ago
    Hi,

    I tried in drawables xml to set foreground color with a variable as described here but in CIQ 2.3 does not work
    BUILD: ERROR: Rez:70: extraneous input

    any advice?

    the goal is the change runtime the color

  • I think the preferred solution now is to use a custom drawable to draw the background. I think this technique is used in one of the sample programs. I'd tell you which one, but I don't have access to the samples at the moment.