Android Tabhost component beautification

Source: Internet
Author: User

Look first:

1.main.xml File Code:

<?xml version= "1.0" encoding= "Utf-8"?> <tabhost xmlns:android= "http://schemas.android.com/apk/res/android "Android:id= "@android: Id/tabhost"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "@drawable/mnv" > <LinearLayout android:orientation= "Vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <framelayout Android:id= "@android: Id/tabcontent"Android:layout_width= "Fill_parent"Android:layout_height= "0.0dip"Android:layout_weight= "1.0"/> <Tabwidget Android:id= "@android: Id/tabs"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "0.0"android:visibility= "Gone"/> <Radiogroup Android:id= "@+id/main_tab"Android:background= "@drawable/maintab_toolbar_bg"android:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:gravity= "Center_vertical"android:layout_gravity= "Bottom" > <RadioButton android:layout_margintop= "0.5dip"Android:text= "@string/main_home"Android:drawabletop= "@drawable/icon_0_n"Android:id= "@+id/radio_button0"style= "@style/main_tab_bottom"/> <RadioButton android:layout_margintop= "0.5dip"Android:text= "@string/main_news"Android:drawabletop= "@drawable/icon_1"Android:id= "@+id/radio_button1"style= "@style/main_tab_bottom"/> <RadioButton android:layout_margintop= "0.5dip"Android:text= "@string/main_shou_cang"Android:drawabletop= "@drawable/icon_3_n"Android:id= "@+id/radio_button2"style= "@style/main_tab_bottom"/> <RadioButton android:layout_margintop= "1.0dip"Android:text= "@string/main_my_info"Android:drawabletop= "@drawable/icon_4_n"Android:id= "@+id/radio_button3"style= "@style/main_tab_bottom"/> <RadioButton android:layout_margintop= "0.5dip"Android:text= "@string/more"Android:drawabletop= "@drawable/icon_5_n"Android:id= "@+id/radio_button4"style= "@style/main_tab_bottom"/> </RadioGroup> </LinearLayout> </TabHost>

2.maintabactivity.java Code:

 Packagecom.jun.activity;Importandroid.app.TabActivity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.Window;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.TabHost;ImportAndroid.widget.RadioGroup.OnCheckedChangeListener;ImportAndroid.widget.Toast; Public classMaintabactivityextendsTabactivityImplementsoncheckedchangelistener{PrivateRadiogroup Maintab; PrivateTabhost Tabhost; PrivateIntent IHome; PrivateIntent iNews; PrivateIntent Iinfo; PrivateIntent ISearch; PrivateIntent Imore; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);         Requestwindowfeature (Window.feature_no_title);         Setcontentview (R.layout.main); Maintab=(Radiogroup) Findviewbyid (R.id.main_tab); Maintab.setoncheckedchangelistener ( This); Tabhost=gettabhost ();//The initialization of the intent is performed here, and the settings intent will be passed into the activity//iHome = new Intent (this, homeactivity.class);//Tabhost.addtab (Tabhost.newtabspec ("IHome")//. Setindicator (Getresources (). getString (R.string.main_home), Getresources (). Getdrawable (R.drawable.icon _1_n))//. SetContent (IHome)); //         //iNews = new Intent (this, newsactivity.class);//Tabhost.addtab (Tabhost.newtabspec ("INews")//. Setindicator (Getresources (). getString (R.string.main_news), Getresources (). Getdrawable (R.drawable.icon _2_n))//. SetContent (iNews)); //         //iinfo = new Intent (this, myinfoactivity.class);//Tabhost.addtab (Tabhost.newtabspec ("Iinfo")//. Setindicator (Getresources (). getString (R.string.main_my_info), Getresources (). Getdrawable (r.drawable.i Con_3_n))//. SetContent (Iinfo)); //         //ISearch = new Intent (this,searchactivity.class);//Tabhost.addtab (Tabhost.newtabspec ("ISearch")//. Setindicator (Getresources (). getString (R.string.menu_search), Getresources (). Getdrawable (R.drawable.ic On_4_n))//. SetContent (ISearch)); //         //imore = new Intent (this, moreactivity.class);//Tabhost.addtab (Tabhost.newtabspec ("Imore")//. Setindicator (Getresources (). getString (R.string.more), Getresources (). Getdrawable (R.drawable.icon_ 5_n))//. SetContent (Imore));} @Override Public voidOnCheckedChanged (Radiogroup Group,intCheckedid) {         Switch(checkedid) { CaseR.id.radio_button0:toast.maketext (maintabactivity. This, "Button0", Toast.length_short). Show ();  Break;  CaseR.id.radio_button1:toast.maketext (maintabactivity. This, "Button1", Toast.length_short). Show ();  Break;  CaseR.id.radio_button2:toast.maketext (maintabactivity. This, "Button2", Toast.length_short). Show ();  Break;  CaseR.id.radio_button3:toast.maketext (maintabactivity. This, "Button3", Toast.length_short). Show ();  Break;  CaseR.id.radio_button4:toast.maketext (maintabactivity. This, "Button4", Toast.length_short). Show ();  Break; }     } }

Project: Click to download

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.