Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Styles and Themes in Android Using Styles in Layouts Including One Layout in Another

3,849 Points

Can someone explain the "include" bit as I couldn't see how it linked two .xml files, or what it actually linked across?

I am most confused on the how to apply it and what it actually does as he only actually talks about it for about 10 seconds. The ordering confused me, but what I make of it is that the "activity_song_playback.xml" now includes all of the styling and xml code from the playback_controls.xml file?

Beginner but also very curious


1 Answer

Boban Talevski
Boban Talevski
24,793 Points

The include thing seems to not be related to styles and themes as he points out, so I wouldn't bother with understanding the part about how themes and styles behave along with include tags (at least I didn't so far). And you seem to have it figured out mostly as it's just what you are saying:

At the spot of the include tag in activity_song_playback.xml, imagine copy pasting the contents of the playback_controls.xml file and there you have it. The include is just saying at this spot, use the code in the layout file I'm pointing to with the first line


The way I see it, It's a feature to keep the code a bit more organized and prevent code duplication if you need to use those same playback controls in another layout. So instead of copy pasting the whole content of playback_controls.xml in multiple layout files, you just make use of the include tag to add it each time.