Ext.: http://www.open-open.com/lib/view/open1330697955842.html
First say the layout file, as follows: Using android:layout_alignparentbottom= "true" to achieve the bottom display
<?XML version= "1.0" encoding= "Utf-8"?><Tabhostxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@android: Id/tabhost"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"> <RelativelayoutAndroid:background= "@drawable/g"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"> <TabwidgetAndroid:id= "@android: Id/tabs"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"> </Tabwidget> <FramelayoutAndroid:id= "@android: Id/tabcontent"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"> <RelativelayoutAndroid:id= "@+id/tabfirst"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical"> <AnalogClockAndroid:id= "@+id/widget31"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"> </AnalogClock> </Relativelayout>><RelativelayoutAndroid:id= "@+id/tabsecond"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical"> <DigitalClockandroid:layout_centerinparent= "true"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"> </DigitalClock> </Relativelayout> </Framelayout> </Relativelayout></Tabhost>
Here is the main program code, comments written in more detail, there is no more explanation
PackageCom.cloay;Importandroid.app.TabActivity;ImportAndroid.graphics.Color;ImportAndroid.os.Bundle;ImportAndroid.widget.TabHost;ImportAndroid.widget.TabHost.OnTabChangeListener;ImportAndroid.widget.Toast; Public classTabtestactivityextendstabactivity {tabhost tabhost; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); //Get Tabhost ObjectTabhost =Gettabhost (); //Tabhost.setup (); //Create a new Newtabspec, set the label and icon (Setindicator), set the content (SetContent)Tabhost.addtab (Tabhost.newtabspec ("Test One"). Setindicator ("", Getresources (). Getdrawable (Android. R.drawable.ic_menu_call)). SetContent (R.id.tabfirst)); Tabhost.addtab (Tabhost.newtabspec ("Test"). Setindicator ("", Getresources (). Getdrawable (Android. R.drawable.ic_menu_camera)). SetContent (R.id.tabsecond)); //set the background color of TabhostTabhost.setbackgroundcolor (Color.argb (150,22,70,150)); //set the background image resource for Tabhost//Tabhost.setbackgroundresource (r.drawable.bg); //set the current reality which labelTabhost.setcurrenttab (0);//0 is the label ID//label switch processing, with SetontabchangedlistenerTabhost.setontabchangedlistener (NewOntabchangelistener () { Public voidontabchanged (String tabId) {toast.maketext (tabtestactivity. This, "This is a test!", Toast.length_long). Show (); } }); }}