Android Implementation Bottom Tabhost

Source: Internet
Author: User

Ext.: http://www.open-open.com/lib/view/open1330697955842.html

First say the layout file, as follows: Using android:layout_alignparentbottom= "true" to achieve the bottom display

<?XML version= "1.0" encoding= "Utf-8"?><Tabhostxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@android: Id/tabhost"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    <RelativelayoutAndroid:background= "@drawable/g"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    <TabwidgetAndroid:id= "@android: Id/tabs"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true">    </Tabwidget>    <FramelayoutAndroid:id= "@android: Id/tabcontent"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">        <RelativelayoutAndroid:id= "@+id/tabfirst"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical">        <AnalogClockAndroid:id= "@+id/widget31"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true">        </AnalogClock>        </Relativelayout>><RelativelayoutAndroid:id= "@+id/tabsecond"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical">            <DigitalClockandroid:layout_centerinparent= "true"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content">            </DigitalClock>        </Relativelayout>    </Framelayout>    </Relativelayout></Tabhost>

Here is the main program code, comments written in more detail, there is no more explanation

 PackageCom.cloay;Importandroid.app.TabActivity;ImportAndroid.graphics.Color;ImportAndroid.os.Bundle;ImportAndroid.widget.TabHost;ImportAndroid.widget.TabHost.OnTabChangeListener;ImportAndroid.widget.Toast; Public classTabtestactivityextendstabactivity {tabhost tabhost; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.main); //Get Tabhost ObjectTabhost =Gettabhost (); //Tabhost.setup (); //Create a new Newtabspec, set the label and icon (Setindicator), set the content (SetContent)Tabhost.addtab (Tabhost.newtabspec ("Test One"). Setindicator ("", Getresources (). Getdrawable (Android.        R.drawable.ic_menu_call)). SetContent (R.id.tabfirst)); Tabhost.addtab (Tabhost.newtabspec ("Test"). Setindicator ("", Getresources (). Getdrawable (Android.        R.drawable.ic_menu_camera)). SetContent (R.id.tabsecond)); //set the background color of TabhostTabhost.setbackgroundcolor (Color.argb (150,22,70,150)); //set the background image resource for Tabhost//Tabhost.setbackgroundresource (r.drawable.bg); //set the current reality which labelTabhost.setcurrenttab (0);//0 is the label ID//label switch processing, with SetontabchangedlistenerTabhost.setontabchangedlistener (NewOntabchangelistener () { Public voidontabchanged (String tabId) {toast.maketext (tabtestactivity. This, "This is a test!", Toast.length_long). Show ();    }        }); }}

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.