Instructions for using the TAB component:
1. Use framelayout in the layout file to list the tab component and the content component in the tab.
2, activity to inherit tabactivity.
3. Call Tabactivity's Gettabhost () method properly Tabhost object.
4. Create tab options via Tabhost.
Let's look at a small example:
<!--xml--><Framelayout xmlns:android="Http://schemas.android.com/apk/res/android" Xmlns:tools="Http://schemas.android.com/tools" Android:layout_width="Match_parent" Android:layout_height="Match_parent" Android:paddingbottom="@dimen/activity_vertical_margin" Android:paddingleft="@dimen/activity_horizontal_margin" Android:paddingright="@dimen/activity_horizontal_margin" Android:paddingtop="@dimen/activity_vertical_margin" Tools:context=". Mainactivity "> <tabhostandroid:id= "@+id/tabhost01"android:layout_width="Wrap_ Content "android:layout_height=" Wrap_content "> </tabhost> <textview android:id
= "@+id/suoyou" android:layout_width =< Span class= "Hljs-value" > "wrap_content" android:layout_height = "wrap_content" android:text =" @string/suoyou "/> <textview android:id
= "@+id/yijie" android:layout_width =< Span class= "Hljs-value" > "wrap_content" android:layout_height = "wrap_content" android:text =" @string/yijie "/> <TextViewandroid:id= "@+id/weijie"android:layout_width="Wrap_ Content "android:layout_height=" Wrap_content "android:text=" @string/weijie " /> </framelayout>
Activity Code Packagecom. Yangzi. Tab;Import Android. App. Tabactivity;Import Android. OS. Bundle;Import Android. View. Layoutinflater;Import Android. View. Menu;Import Android. Widgets. Tabhost;public class Mainactivity extends tabactivity {@Override protected void onCreate (Bundle savedinstancestate) { Super. OnCreate(savedinstancestate);Setcontentview (R. Layout. Activity_main);Get Tabhost object Tabhost th = Gettabhost ();Layoutinflater. from(this). Inflate(R. Layout. Activity_main,th. Gettabcontentview(), True);Add options, set label contents and display content th. AddTab(th. Newtabspec("All"). Setindicator("All calls"). SetContent(R. ID. Suoyou));Th. AddTab(th. Newtabspec("OK"). Setindicator("Received call"). SetContent(R. ID. Yijie));Th. AddTab(th. Newtabspec("Cancel"). Setindicator("Missed calls"). SetContent(R. ID. Weijie));}}
Try it out and see how it works!
Tabs in Android (tab) use case