Add Tabs to Android Application using the layout/main.xml file

houbysoft picture houbysoft · Mar 6, 2011 · Viewed 18.8k times · Source

I am beginning with Android and I'd like to add tabs to my existing application.

Right now I just have one activity with the layout defined in the XML file. I would now like to add other tabs.

I have looked it up and found http://developer.android.com/resources/tutorials/views/hello-tabwidget.html on the Android developer site; however, that doesn't use XML for defining the layout of the tabs.

So, how can I easily add tabs using the XML file only for the layout?

Thanks in advance.

Answer

CommonsWare picture CommonsWare · Mar 6, 2011

I have looked it up and found http://developer.android.com/resources/tutorials/views/hello-tabwidget.html on the Android developer site; however, that doesn't use XML for defining the layout of the tabs.

Yes, it does. See step #4.


UPDATE

Google reorganized their documentation and got rid of this tutorial. You can see the use of XML for defining the tabs in TabWidget in this sample project.