问题
Is it possible to have an xml drawable with parameters? Suppose I have an xml drawable that I want to reuse for the rounded corners, gradients etc, and the only variable is a color or two. Is it possible to specify/pass parameters to an xml drawable?
回答1:
Perhaps you can derive your own class from Drawable, have a constructor accepting the parameters you want to make adjustable and in the constructor first call createFromXML
passing your xml and then setup those adjustable parameters.
I didn't try that myself, perhaps, I'm wrong
来源:https://stackoverflow.com/questions/8396779/android-xml-drawable-parameters