First, the layout file is shown as follows: Use Android: layout_alignparentbottom = "true" to display the bottom
1 <?xml version="1.0" encoding="utf-8"?> 2 <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@android:id/tabhost" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent"> 7 <RelativeLayout 8 android:background="@drawable/g" 9 android:layout_width="fill_parent"10 android:layout_height="fill_parent">11 <TabWidget android:id="@android:id/tabs"12 android:layout_width="fill_parent"13 android:layout_height="wrap_content"14 android:layout_alignParentBottom="true">15 </TabWidget>16 <FrameLayout android:id="@android:id/tabcontent"17 android:layout_width="fill_parent"18 android:layout_height="fill_parent">19 <RelativeLayout android:id="@+id/tabFirst"20 android:layout_width="fill_parent"21 android:layout_height="fill_parent"22 android:orientation="vertical">23 <AnalogClock24 android:id="@+id/widget31"25 android:layout_width="wrap_content"26 android:layout_height="wrap_content"27 android:layout_centerInParent="true">28 </AnalogClock>29 </RelativeLayout>>30 <RelativeLayout android:id="@+id/tabSecond"31 android:layout_width="fill_parent"32 android:layout_height="fill_parent"33 android:orientation="vertical">34 <DigitalClock35 android:layout_centerInParent="true"36 android:layout_width="wrap_content"37 android:layout_height="wrap_content">38 </DigitalClock>39 </RelativeLayout>40 </FrameLayout>41 </RelativeLayout>42 </TabHost>
The following is the main program code, which is detailed in Annotation writing. I will not explain it more here.
1 package COM. cloay; 2 3 Import android. app. tabactivity; 4 Import android. graphics. color; 5 import android. OS. bundle; 6 Import android. widget. tabhost; 7 Import android. widget. tabhost. ontabchangelistener; 8 Import android. widget. toast; 9 10 public class tabtestactivity extends tabactivity {11 tabhost; 12 @ override13 public void oncreate (bundle savedinstancestate) {14 super. oncreate (savedinsta Ncestate); 15 setcontentview (R. layout. main); 16 // get the tabhost object 17 tabhost = gettabhost (); 18 // tabhost. setup (); 19 // create a newtabspec, set the tag and Icon (setindicator), and set the content (setcontent) 20 tabhost. addtab (tabhost. newtabspec ("test one "). setindicator ("", getresources (). getdrawable (Android. r. drawable. ic_menu_call )). setcontent (R. id. tabfirst); 21 tabhost. addtab (tabhost. newtabspec ("test two "). setindicator ("", getresources (). g Etdrawable (Android. r. drawable. ic_menu_camera )). setcontent (R. id. tabsecond); 22 // set the tabhost background color 23 tabhost. setbackgroundcolor (color. argb (70,150,); 24 // sets the background image resource of tabhost. 25 // tabhost. setbackgroundresource (R. drawable. BG); 26 // set the current tag 27 tabhost. setcurrenttab (0); // 0 indicates the tag id28 // tag switching. Use setontabchangedlistener 29 tabhost. setontabchangedlistener (New ontabchangelistener () {30 public void ontabchange D (string Tabid) {31 toast. maketext (tabtestactivity. This, "this is a test! ", Toast. length_long). Show (); 32} 33}); 34} 35}