Tabs in Android (tab) use case

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.