每个个tab对应一个layout。
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost mTabHost = getTabHost(); LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.tab1, mTabHost.getTabContentView()); inflater.inflate(R.layout.tab2, mTabHost.getTabContentView()); inflater.inflate(R.layout.tab3, mTabHost.getTabContentView()); mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("短信") .setContent(R.id.LinearLayout01)); mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("功能") .setContent(R.id.FrameLayout02)); mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("配制") .setContent(R.id.config)); addListener(); }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/openinfo" android:layout_height="wrap_content" android:layout_width="fill_parent"></TextView> …… </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/FrameLayout02" android:orientation="vertical"> <Button android:layout_height="wrap_content" android:text="黑名单列表" android:id="@+id/ShowBlackNum" android:layout_width="fill_parent"></Button> …… </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/config" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical"> <Button android:id="@+id/currentconfig" android:layout_height="wrap_content" android:text="当前配制" android:layout_width="fill_parent"></Button> …… </LinearLayout>