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.
0/250
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
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 FrameLayout that displays the contents of the
- TabWidget - This control displays a list of tab labels, one for each tab in the TabHost . Each tab in a TabHost are represented by a TabHost.TabSpec object. This object contains the meta-data for each tab. When the user selects a tab, the TabHost responds to the selection by displaying the appropriate tab.
- FrameLayout - A tabbed UI must have a FrameLayout contained inside of a TabHost . 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.
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.