XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="7dip"
android:orientation="vertical" >
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:background="@android:color/transparent"
android:tabStripEnabled="false"
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Java:
TabHost tabHost = (TabHost) this.findViewById(R.id.tabhost);
TabWidget tabWidget = (TabWidget) this.findViewById(android.R.id.tabs);
tabWidget.setStripEnabled(false);
LocalActivityManager mLocalActivityManager = new LocalActivityManager(
this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
tabHost.setup(mLocalActivityManager);
// 实例化了tabWidget和tabContent
tabHost.addTab(tabHost
.newTabSpec("one")
.setIndicator(
"",
this.getResources().getDrawable(
R.drawable.button_selector))
.setContent(new Intent(this, FacetabActivity1.class)));
tabHost.addTab(tabHost
.newTabSpec("tab2")
.setIndicator(
"",
this.getResources().getDrawable(
R.drawable.button_selector2))
.setContent(new Intent(this, tabActivity2.class)));
tabHost.addTab(tabHost
.newTabSpec("tab3")
.setIndicator(
"",
this.getResources().getDrawable(
R.drawable.button_selector3))
.setContent(new Intent(this, tabActivity3.class)));