Objective
Welcome everyone I share and recommend useful code Snippets ~ ~
Statement
Welcome reprint, but please keep the original source of the article:
CSDN:http://www.csdn.net
rainy season o mo away:http://blog.csdn.net/luckkof
Body
The structure of the TAB applicationThe structure of the tabhost activity is as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <!--define Tabhost components--<linearlayout xmlns:android= "/http/ Schemas.android.com/apk/res/android "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "> <!--Tabhost must contain a tabwidget and a framelayout--> <tabhost android:id= "@+id/tabhost" android:layout_width= " Fill_parent "android:layout_height=" Wrap_content "> <!--tabwidget id attribute must be @android:id/tabs--> <tabwidget android:id= "@android: Id/tabs" android:orientation= "Horizontal" android:layout_width= "fill _parent "android:layout_height=" Wrap_content "/> <!--framelayout id attribute must be @android: Id/ta bcontent--> <framelayout android:id= "@android: Id/tabcontent" android:layout_width= "Fill_parent" Androi d:layout_height= "Fill_parent" > <linearlayout android:id= "@+id/linear01" android:layout_width= "match _parent "android:layout_height=" Match_parent "Androidoid:layout_margintop= "50DP" ><textview android:id= "@+id/view1" android:layout_width= "Fill_parent" Android: layout_height= "Fill_parent" android:text= "the One"/> </LinearLayout> <linearlayo UT android:id= "@+id/linear02" android:layout_width= "match_parent" android:layout_height= "Match_parent" Android: layout_margintop= "50DP" > <textview android:id= "@+id/view2" android:layout_width= "Fill_parent" Android : layout_height= "Fill_parent" android:text= "the other"/> </LinearLayout> <linearl Ayout android:id= "@+id/linear03" android:layout_width= "match_parent" android:layout_height= "Match_parent" Android: layout_margintop= "50DP" > <textview android:id= "@+id/view3" android:layout_width= "Fill_parent" Android : layout_height= "Fill_parent" android:text= "the three"/> </LinearLayout> </framela Yout> </TabHost> </LinearLayout>
Package Com.example.tabhostdemo;import Android.app.activity;import Android.os.bundle;import android.widget.TabHost ;p ublic class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Tabhost tabhost = (tabhost) Findviewbyid (r.id.tabhost);//If there is no inheritance tabactivity, the startup Tabhosttabhost.setup () is loaded by this method;// Add the first tab of Tabhost.addtab (Tabhost.newtabspec ("Tab01"). Setindicator ("Started"). SetContent (R.id.linear01));//Add a second tab, and add a picture on its label tabhost.addtab (Tabhost.newtabspec ("tab02"). Setindicator ("To Start", Getresources (). Getdrawable ( R.drawable.ic_launcher). SetContent (R.id.linear02));//Add a Third tab Tabhost.addtab (Tabhost.newtabspec ("tab03"). Setindicator ("Completed"). SetContent (R.ID.LINEAR03));}}