Android Learning-Interface-ui-tabhost

Source: Internet
Author: User

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

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.