Color of Drawable List of shapes

Former Member
Former Member
Hi,

If I have a drawable list of shapes ( like a circle and a rectangle ) ,given the id (that i guess is the ID of the group ) how can i change in one step the color of all elements ?

thanks.


Marco

  • I haven't looked at this in a while, but if memory serves the drawable list is implemented as a series of calls to draw{Circle,Rectangle,Polygon,...)() with the color that is defined in the XML. It used to be possible to refer to a variable that would be used as the color, but I'm fairly certain this hack was broken by a resource compiler fix.

    The best solution is to define classes that inherit from Ui.Drawable and draw the shapes that you want. If you are using layouts, use the custom drawables functionality to put these drawables into a layout. Once you have class types that represent the drawables and they are in the layout, you can search for them and call methods on them...

    function onUpdate(dc) {
    var circle = findDrawableById("circle");
    if (circle != null) {
    circle.setColor(mIsSomethingBad ? Gfx.COLOR_RED : Gfx.COLOR_GREEN);
    }

    // more stuff
    }


    Once you have that working, you can start thinking about caching references to the drawables to avoid doing lookups for them all of the time.

    Travis
  • Former Member
    Former Member
    thanks for reply,

    but i can't get how to use in layout.xml if i would like to draw shapes with custom drawable. An example could help.

    Thanks!

    Marco
  • There is an example of using a custom drawable in a layout on the page in the Programmer's Guide that I linked to above.