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