先看效果:
activity_tabhost.xml:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ef"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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" />
</LinearLayout>
</TabHost>
MainActivity.java:
public class IntentTabActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabhost);
TabHost tabHost=getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("已接电话").setContent(new Intent(this,BeCalledActivity.class)));
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("呼出电话").setContent(new Intent(this,CalledActivity.class)));
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("未接电话").setContent(new Intent(this,NoCallActivity.class)));
}
}
其他三个Activity就只是显示两个TextView,这里省略不写