As follows:
Main. xmlCodeAs follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Tabhost xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <! -- Define the content of the first tab --> <linearlayout Android: Id = "@ + ID/tab01" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "daughter country king-2010/12/12" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Dong Hailong female-2010/12/18" Android: textsize = "11pt"/> </linearlayout> <! -- Define the content of the second tab --> <linearlayout Android: Id = "@ + ID/tab02" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Bai Gujing-2010/08/12" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Plain Tarantsearch-2010/09/20 "Android: textsize =" 11pt "/> </linearlayout> <! -- Define the content of the third tab --> <linearlayout Android: Id = "@ + ID/tab03" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical" Android: textsize = "11pt"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Sun Wukong-2010/09/19" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "-2010/10/12" Android: textsize = "11pt"/> </linearlayout> </tabhost>
The androidmanifest. XML Code is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "android. demo "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 15 "/> <application Android: icon = "@ drawable/ic_launcher" Android: Label = "@ string/app_name"> <activity Android: Name = ". mytab "> <intent-filter> <action Android: Name =" android. intent. action. main "> </Action> <category Android: Name =" android. intent. category. launcher "> </Category> </intent-filter> </activity> </Application> </manifest>
The mytab. Java code is as follows:
package android. demo; import android. app. tabactivity; import android. graphics. color; import android. OS. bundle; import android. view. layoutinflater; import android. widget. tabhost; import android. widget. tabhost. ontabchangelistener; @ suppresswarnings ("deprecation") public class mytab extends tabactivity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); tabhost = gettabhost (); // set layoutinflater to use tabhost layout. from (this ). inflate (R. layout. main, tabhost. gettabcontentview (), true); // Add the first tab tabhost. addtab (tabhost. newtabspec ("tab1 "). setindicator ("answered "). setcontent (R. id. tab01); // Add the second tab tabhost. addtab (tabhost. newtabspec ("tab2") // place the icon on the label title. setindicator ("outgoing call", getresources (). getdrawable (R. drawable. ic_launcher )). setcontent (R. id. tab02); // Add the third tab tabhost. addtab (tabhost. newtabspec ("tab3 "). setindicator ("missed "). setcontent (R. id. tab03) ;}}