I am developing an application where certain elements will repeat themselves a lot over the whole interface. Googling a bit i found out about the <include /> tag, which is working nicely for what i want.
I was just wondering if there is a way to export certain properties of the included layout: One of them has an image and a string that change according to the use case, and i’d like to set these in the XML file for each case, instead of having to write boilerplate code to set them in the code; Is there any way to do this? Or am i doomed to write that code?
We’re all doomed. As explained in the article Creating Reusable Components, the only things that you can override are the
layout_*attributes and the id. There’s no way (sadly) to parameterize a layout like you describe.The
<include>tag is is useful for separating configuration-dependent parts of your layout from those parts that are invariant across devices. (E.g., you can<include layout="@layout/footer">and have differentfooter.xmlfiles for different configurations.)