- <?xml version="1.0" encoding="utf-8"?>
- <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <LinearLayout
- android:id="@+id/tab01"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第一个标签01"/>
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第一个标签02"/>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab02"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第二个标签01"/>
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第二个标签02"/>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab03"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第三个标签01"/>
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="第三个标签02"/>
- </LinearLayout>
- </TabHost>
点击选项卡可以跳转到相应页面
- import android.app.TabActivity;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.widget.TabHost;
- public class AndroidtestActivity14 extends TabActivity{
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //获得tabhost
- TabHost tabhost=getTabHost();
- //设置tabhost布局
- LayoutInflater.from(this).inflate(R.layout.main14, tabhost.getTabContentView(),true);
- //添加第一个标签
- tabhost.addTab(tabhost.newTabSpec("tab1")
- .setIndicator("第一个标签")
- .setContent(R.id.tab01));
- //添加第二个标签
- tabhost.addTab(tabhost.newTabSpec("tab2")
- .setIndicator("第二个标签")
- .setContent(R.id.tab02));
- //添加第三个标签
- tabhost.addTab(tabhost.newTabSpec("tab3")
- .setIndicator("第三个标签")
- .setContent(R.id.tab03));
- }
- }