Preethi Preethi - 1 month ago 6x
Android Question

Can I have one XML in drawable folder supporting multiple colors/borders for multiple button?

I have 2 buttons with two different colors and border colors. So I need to create a XML in drawable folder with shape attribute and:

android:color="#C5510E" />

<solid android:color="#F78340" />`

and another XML with:

android:color="#FFFFFF" />

<solid android:color="#000000" />

Is there a way where I can handle them in one XML inside drawable folder rather than two XML?


No, this is not possible. Unlike other components, drawable resources are not given IDs, so they are referenced only by part filename through R.drawable. They must be handled in separate files.

See developer documentation on referencing a shape drawable. (Other drawable types are on that same bit of documentation, if interested.)