Skip to content Skip to sidebar Skip to footer

What Has To Be Used, Content_main Or Activity_main?

Since after the new update in Android studio, the addition of the XML files has brought some confusion. While setting the parameters for setContentView(), which XML has to be used

Solution 1:

While setting the parameters for setContentView, which XML has to be typed ? Content_main or Activity_main ?

You should use content_main.xml to put your views but pass activity_main.xml as the parameter to you setContentView() method.

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

content_main.xml is used to display your stuff i.e. what you want to display to users.

reference

And if I want to add an Layout file (XML) do I have to create 2 files with the same name ?

Totally depends on the nature of the activity you are creating the layout for. The difference above will help you decide whether you need two or one.

Post a Comment for "What Has To Be Used, Content_main Or Activity_main?"