Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, DemoActivity1.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("todaystake").setIndicator("Todays Take",
res.getDrawable(R.drawable.icontodaystake)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, DemoActivity2.class);
spec = tabHost.newTabSpec("whatscasting").setIndicator(
"What's Casting", res.getDrawable(R.drawable.iconwhatscasting))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
您的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">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@android:id/tabs" />
<TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</TabHost>
感謝。你有沒有看到該教程中的代碼,你能告訴我該編寫代碼的位置,我很困惑... @Heiko Rupp – Taruni 2012-02-09 10:04:55