Tabhost, watch out.
1. Put the tabhost on the interface and add a custom tab, and you must also set the tab in code, not the XML.
2.Activity must inherit tabactivity, otherwise there is no gettabhost function
3. It is not recommended to use Tabactivity now, recommended with Flagment, it is said in the book
Example
The first tab Landing window is in another activity, and the others are written in XML.
Activity_main.xml
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" > <TabhostAndroid:id= "@android: Id/tabhost"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <TabwidgetAndroid:id= "@android: Id/tabs"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" > </Tabwidget> <FramelayoutAndroid:id= "@android: Id/tabcontent"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <LinearLayoutAndroid:id= "@+id/tab1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "button" /> </LinearLayout> <LinearLayoutAndroid:id= "@+id/tab2"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Large Text"android:textappearance= "? Android:attr/textappearancelarge" /> </LinearLayout> <LinearLayoutAndroid:id= "@+id/tab3"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <ProgressBarAndroid:id= "@+id/progressbar1"style= "? Android:attr/progressbarstylelarge"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /> </LinearLayout> </Framelayout> </LinearLayout> </Tabhost></LinearLayout>
View Code
Mainactivity.java
Public classMainactivityextendstabactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //Get TabsTabhost tabhost=Gettabhost (); //Create a tab//setindicator Setting the tab title//setcontent Setting up tab1 page ResourcesTabspec Tab1=tabhost.newtabspec ("Tab1"). Setindicator ("Show Buttons"). SetContent (R.ID.TAB1); Tabspec tab2=tabhost.newtabspec ("Tab1"). Setindicator ("Display a text"). SetContent (R.ID.TAB2); Tabspec tab3=tabhost.newtabspec ("Tab1"). Setindicator ("Show the Progress of a circle"). SetContent (R.ID.TAB3); //A login page that comes with the activity directlyIntent intent=NewIntent (mainactivity. This, Loginactivity.class); Tabspec TAB4=tabhost.newtabspec ("Tab4"). Setindicator ("Login Window"). SetContent (Intent); //add to Tabhost insideTabhost.addtab (TAB4); Tabhost.addtab (TAB1); Tabhost.addtab (TAB2); Tabhost.addtab (TAB3); }}View Code
Android Learning-Interface-ui-tabhost