TabDemo in Android

Source: Internet
Author: User

First the style, note must use Android:id/tabs cannot use id+

<tabhost android:layout_height= "match_parent"    android:layout_width= "match_parent"    android:id= "@ Android:id/tabhost "     xmlns:android=" http://schemas.android.com/apk/res/android ">    <linearlayout    android:layout_width= "match_parent"    android:layout_height= "match_parent"    android:orientation= " Vertical ">    <tabwidget         android:layout_width=" match_parent "        android:layout_height=" Wrap_ Content "        android:id=" @android: Id/tabs "        >    </TabWidget>    <framelayout android:id=" @android: id/tabcontent "        android:layout_width=" match_parent "        android:layout_height=" Wrap_content "        android:layout_weight= "1"        >    </FrameLayout></LinearLayout></TabHost>

  

Next write the Code

public class Tabactivity extends Android.app.TabActivity {private tabhost _tabhost; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_tab); _tabhost=gettabhost ();} private void AddTab1 () {//TODO auto-generated method stubintent intent1=new Intent (this,activity1.class); Tabspec sp1=_tabhost.newtabspec ("option 1");//Jump to Sp1.setcontent (intent1);//title Sp1.setindicator ("one"); _tabhost.addtab ( SP1);}}

  

TabDemo in Android

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.