tab.xml:
<?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">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</RelativeLayout>
</TabHost>
添加下面的代碼在你的activity.java文件:
通過android.app.TabActivity
代替Activity
TabHost tabHost=getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent=new Intent().setClass(YourActivity.this, NewActivity.class);
spec=tabHost.newTabSpec("tab1").setIndicator("imageId").setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(YourActivity.this, New1Activity.class);
spec=tabHost.newTabSpec("tab2").setIndicator("imageId").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
拓展業務,以同樣的方式您可以在活動中添加儘可能多的選項卡。
我已經對我的答案做了一些更改,嘿嘿一瞥。 – AkashG 2012-07-23 12:13:03
本教程可能會幫助您http://http.wordpress.com/2013/12/18/how-to-use-tabwidget-with-fragments/ – Prachi 2013-12-23 11:36:29