Android Tabhost (easy to use)

Source: Internet
Author: User

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));}}



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.