Drawable is not drawn after setDrawableByLayerId

by tt6 » Thu, 04 Feb 2010 05:50:29 GMT

Sponsored Links

I'm having a problem with displaying a drawable. I have a ImageButton
and a LayerDrawable. I set up an array of Drawable that has one
Drawable for the background (index 0) and one for the image (index 1).
The button would display different background on different states of
the button. What I've done is when the button state changes I replace
the background Drawable like:

        elements[0] = <background drawable object>
        elements[1] = <image drawable object>
        layers = new LayerDrawable(elements);
        layers.setId(0, 0);
        layers.setId(1, 1);

        LayerDrawable ld = (LayerDrawable)button.getDrawable();
        boolean result = ld.setDrawableByLayerId(0, <new

The problem is the initial old background is gone but the new one is
not displayed. What have I done wrong or missed?

Thank you!