Use of tabhost (Tab) in Android

Source: Internet
Author: User

As follows:

Main. xmlCodeAs follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Tabhost xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <! -- Define the content of the first tab --> <linearlayout Android: Id = "@ + ID/tab01" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "daughter country king-2010/12/12" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Dong Hailong female-2010/12/18" Android: textsize = "11pt"/> </linearlayout> <! -- Define the content of the second tab --> <linearlayout Android: Id = "@ + ID/tab02" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Bai Gujing-2010/08/12" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Plain Tarantsearch-2010/09/20 "Android: textsize =" 11pt "/> </linearlayout> <! -- Define the content of the third tab --> <linearlayout Android: Id = "@ + ID/tab03" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: orientation = "vertical" Android: textsize = "11pt"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Sun Wukong-2010/09/19" Android: textsize = "11pt"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "-2010/10/12" Android: textsize = "11pt"/> </linearlayout> </tabhost>

The androidmanifest. XML Code is as follows:

 
<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "android. demo "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 15 "/> <application Android: icon = "@ drawable/ic_launcher" Android: Label = "@ string/app_name"> <activity Android: Name = ". mytab "> <intent-filter> <action Android: Name =" android. intent. action. main "> </Action> <category Android: Name =" android. intent. category. launcher "> </Category> </intent-filter> </activity> </Application> </manifest>

The mytab. Java code is as follows:

 package android. demo; import android. app. tabactivity; import android. graphics. color; import android. OS. bundle; import android. view. layoutinflater; import android. widget. tabhost; import android. widget. tabhost. ontabchangelistener; @ suppresswarnings ("deprecation") public class mytab extends tabactivity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); tabhost = gettabhost (); // set layoutinflater to use tabhost layout. from (this ). inflate (R. layout. main, tabhost. gettabcontentview (), true); // Add the first tab tabhost. addtab (tabhost. newtabspec ("tab1 "). setindicator ("answered "). setcontent (R. id. tab01); // Add the second tab tabhost. addtab (tabhost. newtabspec ("tab2") // place the icon on the label title. setindicator ("outgoing call", getresources (). getdrawable (R. drawable. ic_launcher )). setcontent (R. id. tab02); // Add the third tab tabhost. addtab (tabhost. newtabspec ("tab3 "). setindicator ("missed "). setcontent (R. id. tab03) ;}}
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.