1

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? Content_main or Activity_main ?

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

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
A. Gupta
  • 13
  • 2

1 Answers1

0

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.

Community
  • 1
  • 1
Viral Patel
  • 32,418
  • 18
  • 82
  • 110