I want to merge between layout file and xml file.
But, my problem, is how can I do it dynamically.
I mean that I have general toolbar file that contains: my app icon, the activity name and linearlayout space for button. I want to merge this toolbar to each activity, so that all activity could put its own buttons in the linearlayout in the toolbar.
I have try to do that, I wrote toolbar file that called toolbar.xml in the layout folder.
And each activity included this toobar like that: <include layout="@layout/toolbar.xml" />, but I do not know how to insert the buttons.
Can I do that with the xml of the activity only?
To add buttons from code (which I guess is what you want to do) you just need to have a container where your buttons shall be inserted into. You can just add
<LinearLayout>to your layout XML file (ensure your layout got id, i.e.:Them, in your code create your button as any other object:
then find your button container:
and add your button to it:
To find out more see ViewGroup documentation