Preethi Preethi - 2 months ago 13
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:

<stroke
android:width="1dp"
android:color="#C5510E" />

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


and another XML with:

<stroke
android:width="1dp"
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?

Answer

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.)

Comments