The use of Android learning--tabhost two

Source: Internet
Author: User

Imitation QQ Bottom navigation bar

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5A/3A/wKiom1T6sPPS1OTnAAEoTExVHIA053.jpg "style=" float: none; "title=" Qq20150307160101.png "alt=" Wkiom1t6spps1otnaaeotexvhia053.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/36/wKioL1T6sgygX9dhAAEylMXKhxk160.jpg "style=" float: none; "title=" Qq20150307160110.png "alt=" Wkiol1t6sgygx9dhaaeylmxkhxk160.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/3A/wKiom1T6sPPBShZ_AAEE8wtu46o405.jpg "style=" float: none; "title=" Qq20150307160118.png "alt=" Wkiom1t6sppbshz_aaee8wtu46o405.jpg "/>

Nonsense not much to say directly on the code

<?xml version= "1.0"  encoding= "UTF-8"?><!-- tab navigation   Latest Version  --><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"  >    <RelativeLayout         android:layout_width= "Fill_parent"         android:layout_ height= "wrap_content"         android:orientation= "vertical" >         <FrameLayout             android:id= "@android: Id/tabcontent"              android:layout_width= "Fill_parent"              android:layout_height= "Fill_parent"             android: Background= "#FFF"  >        </FrameLayout>         <!-- tabwidget Management of the tab, ID name is specified by Android  -->         <TabWidget             android:id= "@android: Id/tabs"              android:layout_width= "Fill_parent"              android:layout_height= "Fill_parent"              android:visibility= "Gone"  />        <!--  Place a single-selection group under frame instead of tab effect  -->        <RadioGroup              android:id= "@+id/main_radio"              android:layout_width= "Fill_parent"              android:layout_height= "Wrap_content"              android:background= "#ccc"             android : gravity= "Center_vertical"             android:o rientation= "Horizontal"             android:layout_ Alignparentbottom= "true"  >            < radiobutton                 Android:id= "@+id/tab_icon_qq"                  style= "@stYle/main_tab "                 Android:checked= "true"                  android:drawabletop= "@drawable/message"                  android:text= "News"  />             <RadioButton                 android:id= "@+id/tab_icon_address"                  style= "@style/main_tab_bottom"                  android:checked= "false"                 android: drawabletop= "@drawable/Home"   &nbsP;             android:text= "Class"  />                  < radiobutton                 Android:id= "@+id/tab_icon_myself"                  style= "@style/main_tab_bottom"                  android:drawabletop= "@drawable/d1"                  android:checked= "false"                  android:text= "Me"  />         </radiogroup>    </relativelayout ></TabHost>

Mainactivity

Public class mainactivity  extends tabactivity {    public  static TabHost mTabHost;    public static TabHost  Getmtabhost ()  {        return mTabHost;     }    private RadioGroup main_radio;    private  Radiobutton tab_icon_qq, tab_icon_address,tab_icon_myself;    /** called  when the activity is first created. */     @Override     public void oncreate (bundle savedinstancestate)  {         super.oncreate (savedinstancestate);         setcontentview (r.layout.activity_main);         mtabhost  = gettabhost ();          final tabwidget tabwidget = mtabhost.gettabwidget ();         tabwidget.setstripenabled (False);             mtabhost.addtab (Mtabhost.newtabspec ("TAG1"). SetIndicator ("0"). SetContent (New intent (This,messageactivity.class)));         Mtabhost.addtab (Mtabhost.newtabspec ("TAG2"). Setindicator ("1"). SetContent (New intent (This, Classactivity.class));           mtabhost.addtab ( Mtabhost.newtabspec ("TAG3"). Setindicator ("2"). SetContent (New intent (This,myselfactivity.class)));         main_radio =  (Radiogroup)  findviewbyid (r.id.main_ Radio);        tab_icon_weixin =  (RadioButton)   Findviewbyid (r.id.tab_icon_weixin);         tab_icon_address =  (RadioButton)  findviewbyid (r.id.tab_icon_address);         tab_icon_myself =  (RadioButton)  findviewbyid (r.id.tab _icon_myself);         main_radio.setoncheckedchangelistener (new  Radiogroup.oncheckedchangelistener ()  {              @Override             public void  OnCheckedChanged (Radiogroup group, int id)  {                 if  (Id == tab_icon_weixin.getid ())  {                      mtabhost.setcurrenttab (0);                 } else if  (Id == tab_icon_address.getid ())  {                     mtabhost.setcurrenttab (1);                 } else  if  (Id == tab_icon_myself.getid ())  {                     mtabhost.setcurrenttab (2);                 }             }        });         //  set which tab is currently displayed          Mtabhost.setcurrenttab (0);        //  traverse tabwidget each label,         for  (Int i = 0; i < tabwidget.getchildcount ();  i++ )  {            View vv =  Tabwidget.getchildat (i);             Vv.getlayoutparams () .height = 45;             // vv.getlayoutparams () .width = 65;             vv.setbackgroundcolor (Color.Blue);        }//       findviewbyid (R.id.tab_icon_brand). Setonclicklistener (This);     }}


This article is from the "Ahu-on-the-road" blog, be sure to keep this source http://xiaocool.blog.51cto.com/1593956/1618270

The use of Android learning--tabhost two

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.