开发者

multiple drawables from one xml file

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 variou开发者_Go百科s 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.


Maybe use GradientDrawable instead of ShapeDrawable.


Actually it is possible to do what you asked for,
this post shows you how to do it.

I tried it and it works perfectly. I haven't found though how to refer to a single drawable from the list.
It seems Level lists are meant to be used into a single object to represent different states of the object. Alhtough in this case we are using it as a drawable container to avoid having many small files.
Maybe future anrdroid releases will support a dedicated drawable container.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜