Tab Layout with TabHost
A Guide to Using the TabHost Widget
- PDF for offline use
- Related Articles:
- Related APIs:
- Related Links:
Let us know how you feel about this
Translation Quality
0/250
last updated: 2017-08
This article will provide a high level overview of the the TabHost, an older API used to create tabbed layouts in a Xamarin.Android application.
Overview
ℹ️Note:
TabHostis an old API that has been deprecated by Google. Developers are encouraged to build tabbed applications using the ActionBar. TheActionBaris available in all version of Android. It was first introduced in Android 3.0 (API level 11) and was back ported to Android 2.2 (API level 8) and Android 2.3 (API level 10) in the V7 AppCompat Library, which is available to Xamarin.Android via the Xamarin Android Support Library - V7 package.
The TabHost is the older, original API for creating tabbed user
interfacesIt is best suited for Xamarin.Android Applications that must
support Android 2.2 and Android 2.3 and cannot use ActionBarSherlock.
The following five components are all involved with the TabHost API:
TabActivity – This is a specialized view that acts as a container for a
TabHost(described below).TabHost – This is a container for the tabbed UI. It hosts two children: a list of tab labels and a
FrameLayoutthat displays the tab content.TabWidget – This control displays a list of tab labels, one for each tab in the
TabHost. Each tab in aTabHostare represented by aTabHost.TabSpecobject. This object contains the meta-data for each tab. When the user selects a tab, theTabHostresponds to the selection by displaying the appropriate tab.FrameLayout – A tabbed UI must have a
FrameLayoutcontained inside of aTabHost. It is used to display the contents for the tab.Activities or Views – When a tab is selected, it displays either an Activity or a View in the
FrameLayout.
The following diagram shows how all of these components relate together:

The tab content may be either Activities or Views. Views are relatively lightweight and simple, but may result in a lot of unrelated code co-habitating in the Activity. This will result in a poor separation of concerns and a bloated class that is hard to maintain. In contrast, Activities require system resources but allow for a more modular approach with the logic for each tab encapsulated in it's own distinct class.
Summary
This article explained the high level components of the older TabHost
API for Android and how they all relate together.
Let us know how you feel about this
Translation Quality
0/250
Xamarin Workbook
If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.

