http://liangruijun.blog.51cto.com/3061169/747173
- <?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:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="fill_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- >
- <TextView
- android:id="@+id/view1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="nihao"
- />
- <TextView
- android:id="@+id/view2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="nihenhao"
- />
- </FrameLayout>
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
- </TabHost>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- 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="@string/hello"
- />
- </LinearLayout>
- package com.lingdududu.test;
- import android.app.TabActivity;
- import android.os.Bundle;
- import android.widget.TabHost;
- public class TestHostActivity extends TabActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tabs);
- TabHost tabhost = getTabHost();
- tabhost.addTab(tabhost.newTabSpec("111").setIndicator("view1").setContent(R.id.view1));
- tabhost.addTab(tabhost.newTabSpec("222").setIndicator("view2").setContent(R.id.view2));
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TabHost
- android:id="@+id/tabhost"
- 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:paddingBottom="62px"
- >
- <TextView
- android:id="@+id/tab1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="这是TabOne"
- />
- <TextView
- android:id="@+id/tab2"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="这是TabTwo"/>
- </FrameLayout>
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_alignParentBottom="true"
- android:layout_width="fill_parent"
- android:layout_height="65.0px"
- android:background="@drawable/tab_bg"
- />
- </RelativeLayout>
- </TabHost>
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- 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="@string/hello"
- />
- </LinearLayout>
- package com.lingdududu.test;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TabHost;
- public class TabHostActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tabs);
- TabHost tabs=(TabHost)findViewById(R.id.tabhost);
- tabs.setup();
- TabHost.TabSpec spec=tabs.newTabSpec("tag1");
- spec.setContent(R.id.tab1);
- spec.setIndicator("TabOne");
- tabs.addTab(spec);
- spec=tabs.newTabSpec("tag2");
- spec.setContent(R.id.tab2);
- spec.setIndicator("TabTwo");
- tabs.addTab(spec);
- tabs.setCurrentTab(0);
- }
- }