TabHost is used to display the Tab page.
Source code download
I. Overview
Provides the window view container of the Tab page. It has two children. One group is the label of the Tab page that you can select and the other group is FrameLayout, which is used to display the content of the Tab page. Some elements usually control the use of this container object, rather than the value set in the child element itself.
Ii. Important Methods
AddTab (TabHost. TabSpec tabSpec): Add a Tab
ClearAllTabs (): clears all associated tabs.
GetCurrentTab (): returns the current Tab page.
GetTabContentView (): returns the FrameLayout containing the content.
NewTabSpec (String tag): returns a new TabSpec associated with it.
Iii. Instances
1. layout file, use FrameLayout
<? Xml version = "1.0" encoding = "UTF-8"?>
<FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<TextView android: id = "@ + id/view1"
Android: background = "@ drawable/B"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 1"/>
<TextView android: id = "@ + id/view2"
Android: background = "@ drawable/c"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 2"/>
<TextView android: id = "@ + id/view3"
Android: background = "@ drawable/d"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 3"/>
</FrameLayout>
2. inherit TabActivity
Public class TabHostDemo extends TabActivity
3. Obtain this abHost
TabHost tabHost = getTabHost ();
4. Set Layout
LayoutInflater. from (this). inflate (R. layout. tabhostpage, tabHost. getTabContentView (), true );
5. Add a Tab
TabHost. addTab (tabHost. newTabSpec ("tab1 ")
. SetIndicator ("tab1 ")
. SetContent (R. id. view1 ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab2 ")
. SetContent (R. id. view2 ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab3 ")
. SetContent (R. id. view3 ));