views:

56

answers:

1

I want to use a number of ShapeDrawables in my application, which are all similar, but with different colours etc. Obviously I could just define them all in separate xml files, but is there a more efficient way to have one xml definition, instantiate various objects and change the colour either in code or xml? You could perhaps do this by calling mutate() on one ShapeDrawable defined in xml, but this returns a Drawable, rather than a shape drawable.

A: 

Maybe use GradientDrawable instead of ShapeDrawable.

Jett
As far as I know (unless I'm missing something in the docs) that just enables you to add a colour gradient to your shapes - not quite what I was after.
Stev_k
looks like one way to do it is using the setColorFilter(color, PorterDuff.Mode.Multiply) method on a single drawable defined in xml and inflated at runtime. For more info see http://stackoverflow.com/questions/1521640/standard-android-button-with-a-different-color
Stev_k