步骤一:MainActivity 界面的模板:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
步骤二:Tb1Activity界面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Tab_1"
android:textSize="30sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="50dip"
android:text="Button" />
<p>
</p></LinearLayout>
步骤三:Tab2Activity界面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Tab_2"
android:textSize="30sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="50dip"
android:text="Button" />
</LinearLayout>
package com.example.tabactivity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
TabHost tabHost = this.getTabHost();
TabSpec tabSpec_1 = tabHost.newTabSpec("Tab_1");
tabSpec_1.setIndicator("Tab_1", res.getDrawable(android.R.drawable.stat_sys_download));
tabSpec_1.setContent(new Intent(this, Tab1Activity.class));
tabHost.addTab(tabSpec_1);
TabSpec tabSpec_2 = tabHost.newTabSpec("Tab_2");
tabSpec_2.setIndicator("Tab_2", res.getDrawable(android.R.drawable.stat_sys_download_done));
tabSpec_2.setContent(new Intent(this, Tab2Activity.class));
tabHost.addTab(tabSpec_2);
}
}