Just started to find some code from the Internet, using the tabactivity, but the operation is always abnormal exit, later see Help said version 4.0 tabactivity is outdated, to use fragment replacement .... Then fix it and change it. has been unable to run properly ...
Later decided to use Tabactivity to try, a mistake to find, finally good ...
Layout: Main_tab.xml
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" Fill_parent "> <!--ID to use the ID of the Android system--& Gt
<tabhost android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:id= "@android: Id/tabh OST "> <relativelayout android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:orientation= "vertical" android:padding= "3DP" > <!--content: ID to use the ID of the Android system-- <framelayout android:id= "@android: Id/tabcontent" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" android:layout_above= "@+id/main_radio" android:layout_weight = "1" android:background= "#FFF" > </FrameLayout> <!--tag: ID to use the ID of the Android system--&G T <tabwidget android:id= "@android: Id/tabs" android:layout_width= "Fill_parent" android:l ayout_height= "Wrap_content" android:visibility= "Gone"/> <!--buttons--<radiogr Oup Android:id= "@+id/main_radio" android:layout_width= "fill_parent" android:layout_height= "Wrap_conten T "android:background=" #ccc "android:orientation=" Horizontal "android:layout_alignparentb Ottom= "true" > <radiobutton android:id= "@+id/tab_btn_quality" s tyle= "@style/main_tab_bottom" android:checked= "false" android:text= "@string/menu_quality"/& Gt <radiobutton android:id= "@+id/tab_btn_sop" style= "@style/main_tab_bottom" Android:checked= "true" android:text= "@string/menu_sop"/> <radiobutton Android:id= "@+id/tab_btn_video" style= "@style/main_tab_bottom" android:checked= "FA LSE "android:text=" @string/menu_video "/> <radiobutton AndroidOid:id= "@+id/tab_btn_logout" style= "@style/main_tab_bottom" android:checked= "false" android:text= "@string/menu_logout"/> </RadioGroup> </relativelayout></tabhost>& Lt;/relativelayout>
Style: Style.xml
<style name= "Main_tab_bottom" > <item name= "android:textsize" >13sp</item> <item name= "Android:textstyle" >bold</item> <item name= "Android:textcolor" > @android: Color/white</item > <item name= "android:gravity" >center_horizontal</item> <item name= "Android:paddingtop ">5dp</item> <item name=" android:layout_width ">fill_parent</item> <item name=" Android:layout_height ">wrap_content</item> <item name=" Android:layout_weight ">1.0</item > <item name= "Android:button" > @null </item> <item name= "Android:layout_margintop" > 1.0dip</item> <item name= "Android:paddingbottom" >5.0dip</item> <item name= " Android:background "> @drawable/selector_tab_btn</item></style>
Button background: selector_tab_btn.xml
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android > <!--selection background-- <item android:drawable= "@drawable/tab_bg_sel" android:state_checked= " True "/> <!--default state background-- <item android:drawable=" @drawable/tab_bg "></item></ Selector>
Code: Mainactivity.java
Package Com.example.test;import Android.os.bundle;import Android.app.activity;import android.app.TabActivity; Import Android.view.menu;import Android.widget.radiobutton;import Android.widget.radiogroup;import Android.widget.tabhost;import Android.widget.tabwidget;import Android.content.intent;import Android.content.res.resources;//public class Mainactivity extends Activity@suppresswarnings ("deprecation") public Class Mainactivity extends tabactivity{public static tabhost mtabhost;public static Tabhost getmtabhost () {return Mtabhost;} Private Radiogroup mmain_radiogroup;private RadioButton mtab_btn_quality,mtab_btn_sop,mtab_btn_video,mtab_btn_ logout; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main_tab); Resources resources = Getresources (); mtabhost = Gettabhost ();//get rid of the fillet edges, as if there is no use, the interface does not see what tabwidget tabwidget = Mtabhost.gettabwidget (); tabwidget.setstripenabled (false);//Add Tab Mtabhost.addtab (Mtabhost.newtabspec (resources.GetString (r.string.menu_tag_quality)). Setindicator (Resources.getstring (r.string.menu_tag_quality)). SetContent ( New Intent (this, tab_quality.class)); Mtabhost.addtab (Mtabhost.newtabspec (resources.getstring (r.string.menu_tag_ SOP). Setindicator (Resources.getstring (R.string.menu_tag_sop)). SetContent (New Intent (this, tab_sop.class)); Mtabhost.addtab (Mtabhost.newtabspec (resources.getstring (R.string.menu_tag_video)). SetIndicator ( Resources.getstring (R.string.menu_tag_video)). SetContent (New Intent (this, tab_video.class));//mtabhost.addtab ( Mtabhost.newtabspec (resources.getstring (R.string.menu_tag_logout)). Setindicator (Resources.getstring ( r.string.menu_tag_logout). SetContent (New Intent (this, loginactivity.class));//correlation control with variable Mmain_radiogroup = ( Radiogroup) Findviewbyid (r.id.main_radio); mtab_btn_quality = (RadioButton) Findviewbyid (r.id.tab_btn_quality); MTab _btn_sop = (RadioButton) Findviewbyid (r.id.tab_btn_sop); mtab_btn_video = (RadioButton) Findviewbyid (r.id.tab_btn_ Video); mtab_btn_logout = (radiobutton) Findviewbyid (r.id.tab_btn_logout);//radio button Select Event Mmain_radiogroup.setoncheckedchangelistener (new Radiogroup.oncheckedchangelistener () {@Overridepublic void oncheckedchanged (radiogroup group, int checkedid) {//TODO Auto-generated method Stubresources resources = Getresources (); if (Checkedid = = Mtab_btn_quality.getid ()) { Mtabhost.setcurrenttabbytag (resources.getstring (r.string.menu_tag_quality));} else if (Checkedid = = Mtab_btn_sop.getid ()) {Mtabhost.setcurrenttabbytag (resources.getstring (R.STRING.MENU_TAG_SOP) );} else if (Checkedid = = Mtab_btn_video.getid ()) {Mtabhost.setcurrenttabbytag (resources.getstring (R.string.menu_tag_ Video));} else if (Checkedid = = Mtab_btn_logout.getid ()) {//mtabhost.setcurrenttabbytag (resources.getstring (R.string.menu_tag _logout));//exit to login interface Intent Intent = new intent (); Intent.setclass (Mainactivity.this, Loginactivity.class); StartActivity (Intent); MainActivity.this.finish ();}}); /setup default open Label Mtabhost.setcurrenttabbytag (resources.getstring (R.string.menu_tag_sop));} @OverridepubLic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is present.getmen Uinflater (). Inflate (R.menu.main, menu); return true;}}
As for the actual content in the tab, just create a few activity.
Then you can run it ....
Android Tabhost Bottom Display