The content of the layout XML file used is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "Http://schemas.android.com/apk/res/android "Android:id= "@android: Id/tabhost"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <LinearLayout android:orientation= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <framelayout Android:id= "@android: Id/tabcontent"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1" > </FrameLayout> <Tabwidget Android:id= "@android: Id/tabs"Android:layout_width= "Fill_parent"Android:layout_alignparentbottom= "true"Android:layout_height= "Wrap_content"/> </LinearLayout></TabHost>
Code that is described in Activity:
//Remember to define these variables firstPrivatetabhost tabhost;PrivateTabwidget Tabwidget; Field Mbottomleftstrip; Field Mbottomrightstrip; Publictabhost Maketab () {if( This. Tabhost = =NULL) {Tabhost=(Tabhost) Findviewbyid (Android. R.id.tabhost); Tabwidget=(Tabwidget) Findviewbyid (Android. R.id.tabs); Tabhost.setup (); Tabhost.bringtofront (); Tabspec Nearby_tab= Tabhost.newtabspec ("Nearby_tab"); Tabspec History_tab= Tabhost.newtabspec ("History_tab"); Tabspec About_tab= Tabhost.newtabspec ("About_tab"); Nearby_tab.setindicator ("First", Getresources (). getdrawable (R.drawable.first)). SetContent (NewIntent ( This, first.class)); History_tab.setindicator ("Second", Getresources (). getdrawable (R.drawable.second)). SetContent (NewIntent ( This, second.class)); About_tab.setindicator ("Third", Getresources (). getdrawable (R.drawable.third)). SetContent (NewIntent ( This, third.class)); Tabhost.addtab (Nearby_tab); Tabhost.addtab (History_tab); Tabhost.addtab (About_tab); if(Integer.valueof (Build.VERSION.SDK) <= 7) { Try{Mbottomleftstrip= Tabwidget.getclass (). Getdeclaredfield ("Mbottomleftstrip"); Mbottomrightstrip= Tabwidget.getclass (). Getdeclaredfield ("Mbottomrightstrip"); if(!mbottomleftstrip.isaccessible ()) {mbottomleftstrip.setaccessible (true); } if(!mbottomrightstrip.isaccessible ()) {mbottomrightstrip.setaccessible (true); } mbottomleftstrip.set (Tabwidget, Getresources (). getdrawable (R.drawable.linee)); Mbottomrightstrip.set (Tabwidget, Getresources (). getdrawable (R.drawable.linee)); } Catch(Exception e) {e.printstacktrace (); } } Else { Try{Mbottomleftstrip= Tabwidget.getclass (). Getdeclaredfield ("Mleftstrip"); Mbottomrightstrip= Tabwidget.getclass (). Getdeclaredfield ("Mrightstrip"); if(!mbottomleftstrip.isaccessible ()) {mbottomleftstrip.setaccessible (true); } if(!mbottomrightstrip.isaccessible ()) {mbottomrightstrip.setaccessible (true); } mbottomleftstrip.set (Tabwidget, Getresources (). getdrawable (R.drawable.linee)); Mbottomrightstrip.set (Tabwidget, Getresources (). getdrawable (R.drawable.linee)); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); } } for(inti = 0; I <tabwidget.getchildcount (); i++) { FinalTextView TV =(TextView) Tabwidget.getchildat (i). Findviewbyid (Android. R.id.title); Tv.settextcolor (Color.White); View VVV=Tabwidget.getchildat (i); if(Tabhost.getcurrenttab () = =i) {vvv.setbackgrounddrawable (Getresources (). getdrawable (R.drawable.focus)); } Else{vvv.setbackgrounddrawable (Getresources (). getdrawable (R.drawable.unfocus)); }} tabhost.setontabchangedlistener (NewOntabchangelistener () {@Override Public voidontabchanged (String tabId) {//TODO auto-generated Method Stub for(inti = 0; I < Tabwidget.getchildcount (); i++) {View VVV=Tabwidget.getchildat (i); if(Tabhost.getcurrenttab () = =i) {vvv.setbackgrounddrawable (Getresources (). getdrawable (R.drawable.focus)); } Else{vvv.setbackgrounddrawable (Getresources (). getdrawable (R.drawable.unfocus)); } } } }); } Else{ returnTabhost; } return NULL;}
<ignore_js_op> testtab.zip (107.97 KB, downloaded: 778)