Difference between content_main.xml and activity_main.xml?

I am new to Android App development. I have Android Studio 1.4. In my layout folder I have two XML files (content_main.xml and activity_main.xml). I have been following Bucky's tutorial and he just has the activity_main.xml. Which one should I use?


Solution 1:

Unlike previous version, the new API 23 comes with the coordinatorLayout and stuff and just to make them simple to use android has distinguished activity's layout into two different layout i.e. content_main.xml & activity_main.xml.

I'll explain what they are for:

  1. activity_main.xml

this xml file is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc..

  1. content_main.xml

This xml file is use to display your stuff i.e. what you want to display to users.

So, if you are just asking in which xml you have to put your stuff, content_main.xml is the one....

Solution 2:

I think the content_main.xml is a part of activity_main.xml. Because there is include layout="@layout/content_main" in the activity_main.xml.

Solution 3:

Android Studio 1.4 gives a default new option of content_main.xml in the activity. actually activity load the xml file of activity_main.xml for your layout. content_main.xml is the part of main.xml. you can use both for layout,but main.xml is necessary for your Activity. its a option to choose the content_main.xml for design of layout. Hope you get it.

Solution 4:

The activity_main.xml is the "outer" part of the activity layout (toolbar, action button, etc.) and content_main.xml is the inner part where you put your own layout (the blank space).

content_main.xml file will be generated when you choose "blank activity". This activity will be having floating button by default at the bottom of the screen.

But when you choose "empty activity" then content_main.xml won't be generated and it won't be having floating button, but just simple Activity.

Solution 5:

activity_main and content_main are linked to each other.

You can use either both. But to be specific, you should use activity_main.

let me explain this further.

activity_main, this is where the content_main is placed. This is a mother and child case, where activity_main is the mother and content_main is the child.

content_main, this is where you put your controls / content e.g button. This represents as the body of your design.