Android APIs
public class

TabHost

extends FrameLayout
implements ViewTreeObserver.OnTouchModeChangeListener
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.TabHost
Known Direct Subclasses

Class Overview

Container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select a specific tab, and a FrameLayout object that displays the contents of that page. The individual elements are typically controlled using this container object, rather than setting values on the child elements themselves.

Summary

Nested Classes
interface TabHost.OnTabChangeListener Interface definition for a callback to be invoked when tab changed  
interface TabHost.TabContentFactory Makes the content of a tab when it is selected. 
class TabHost.TabSpec A tab has a tab indicator, content, and a tag that is used to keep track of it. 
[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TabHost(Context context)
TabHost(Context context, AttributeSet attrs)
TabHost(Context context, AttributeSet attrs, int defStyleAttr)
TabHost(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public Methods
void addTab(TabHost.TabSpec tabSpec)
Add a tab.
void clearAllTabs()
Removes all tabs from the tab widget associated with this tab host.
boolean dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
void dispatchWindowFocusChanged(boolean hasFocus)
Called when the window containing this view gains or loses window focus.
CharSequence getAccessibilityClassName()
Return the class name of this object to be used for accessibility purposes.
int getCurrentTab()
String getCurrentTabTag()
View getCurrentTabView()
View getCurrentView()
FrameLayout getTabContentView()
Get the FrameLayout which holds tab content
TabWidget getTabWidget()
TabHost.TabSpec newTabSpec(String tag)
Get a new TabHost.TabSpec associated with this tab host.
void onTouchModeChanged(boolean isInTouchMode)
Callback method to be invoked when the touch mode changes.
void setCurrentTab(int index)
void setCurrentTabByTag(String tag)
void setOnTabChangedListener(TabHost.OnTabChangeListener l)
Register a callback to be invoked when the selected state of any of the items in this list changes
void setup()

Call setup() before adding tabs if loading TabHost using findViewById().

void setup(LocalActivityManager activityGroup)
If you are using setContent(android.content.Intent), this must be called since the activityGroup is needed to launch the local activity.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.view.ViewTreeObserver.OnTouchModeChangeListener

Public Constructors

public TabHost (Context context)

Added in API level 1

public TabHost (Context context, AttributeSet attrs)

Added in API level 1

public TabHost (Context context, AttributeSet attrs, int defStyleAttr)

Added in API level 21

public TabHost (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Added in API level 21

Public Methods

public void addTab (TabHost.TabSpec tabSpec)

Added in API level 1

Add a tab.

Parameters
tabSpec Specifies how to create the indicator and content.

public void clearAllTabs ()

Added in API level 1

Removes all tabs from the tab widget associated with this tab host.

public boolean dispatchKeyEvent (KeyEvent event)

Added in API level 1

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public void dispatchWindowFocusChanged (boolean hasFocus)

Added in API level 1

Called when the window containing this view gains or loses window focus. ViewGroups should override to route to their children.

Parameters
hasFocus True if the window containing this view now has focus, false otherwise.

public CharSequence getAccessibilityClassName ()

Added in API level 23

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

public int getCurrentTab ()

Added in API level 1

public String getCurrentTabTag ()

Added in API level 1

public View getCurrentTabView ()

Added in API level 1

public View getCurrentView ()

Added in API level 1

public FrameLayout getTabContentView ()

Added in API level 1

Get the FrameLayout which holds tab content

public TabWidget getTabWidget ()

Added in API level 1

public TabHost.TabSpec newTabSpec (String tag)

Added in API level 1

Get a new TabHost.TabSpec associated with this tab host.

Parameters
tag required tag of tab.

public void onTouchModeChanged (boolean isInTouchMode)

Added in API level 1

Callback method to be invoked when the touch mode changes.

Parameters
isInTouchMode True if the view hierarchy is now in touch mode, false otherwise.

public void setCurrentTab (int index)

Added in API level 1

public void setCurrentTabByTag (String tag)

Added in API level 1

public void setOnTabChangedListener (TabHost.OnTabChangeListener l)

Added in API level 1

Register a callback to be invoked when the selected state of any of the items in this list changes

Parameters
l The callback that will run

public void setup ()

Added in API level 1

Call setup() before adding tabs if loading TabHost using findViewById(). However: You do not need to call setup() after getTabHost() in TabActivity. Example:

mTabHost = (TabHost)findViewById(R.id.tabhost);
mTabHost.setup();
mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");

public void setup (LocalActivityManager activityGroup)

Added in API level 1

If you are using setContent(android.content.Intent), this must be called since the activityGroup is needed to launch the local activity. This is done for you if you extend TabActivity.

Parameters
activityGroup Used to launch activities for tab content.