main.xml

  1. <?xmlversion="1.0"encoding="utf-8"?>

  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

  3. android:orientation="vertical"

  4. android:layout_width="fill_parent"

  5. android:layout_height="fill_parent"

  6. >

  7. <TabHostandroid:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="match_parent">

  8. <LinearLayoutandroid:layout_width="match_parent"android:id="@+id/linearLayout1"android:layout_height="match_parent"android:orientation="vertical">

  9. <TabWidgetandroid:layout_width="match_parent"android:id="@android:id/tabs"android:layout_height="wrap_content"></TabWidget>

  10. <FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@android:id/tabcontent">

  11. <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tab1">

  12. <ImageViewandroid:id="@+id/p_w_picpathView2"android:src="@drawable/intnet"android:layout_width="match_parent"android:layout_height="match_parent"></ImageView>

  13. </LinearLayout>

  14. <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tab2">

  15. <ImageViewandroid:id="@+id/p_w_picpathView4"android:src="@drawable/reresh"android:layout_height="match_parent"android:layout_width="match_parent"></ImageView>

  16. </LinearLayout>

  17. <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tab3">

  18. <ImageViewandroid:id="@+id/p_w_picpathView5"android:src="@drawable/search"android:layout_height="match_parent"android:layout_width="match_parent"></ImageView>

  19. </LinearLayout>

  20. <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tab4">

  21. <ImageViewandroid:id="@+id/p_w_picpathView3"android:src="@drawable/picture"android:layout_height="match_parent"android:layout_width="match_parent"></ImageView>

  22. </LinearLayout>

  23. <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tab5">

  24. <ImageViewandroid:id="@+id/p_w_picpathView1"android:src="@drawable/info"android:layout_height="match_parent"android:layout_width="match_parent"></ImageView>

  25. </LinearLayout>

  26. </FrameLayout>

  27. </LinearLayout>

  28. </TabHost>

  29. </LinearLayout>


Activity



  1. package rw.Tab;  

  2. import android.app.TabActivity;  

  3. import android.os.Bundle;  

  4. import android.widget.TabHost;  

  5. publicclass Tabhost02Activity extends TabActivity {  

  6. /** Called when the activity is first created. */

  7. private TabHost tabHost;  

  8. @Override

  9. publicvoid onCreate(Bundle savedInstanceState) {  

  10. super.onCreate(savedInstanceState);  

  11.        setContentView(R.layout.main);  

  12.        tabHost=getTabHost();  

  13.        tabHost.addTab(tabHost.newTabSpec("network").setIndicator("流量",getResources().getDrawable(R.drawable.intnet)).setContent(R.id.tab1));  

  14.        tabHost.addTab(tabHost.newTabSpec("refesh").setIndicator("刷新",getResources().getDrawable(R.drawable.reresh)).setContent(R.id.tab2));  

  15.        tabHost.addTab(tabHost.newTabSpec("search").setIndicator("搜索",getResources().getDrawable(R.drawable.search)).setContent(R.id.tab3));  

  16.        tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("图片",getResources().getDrawable(R.drawable.picture)).setContent(R.id.tab4));  

  17.        tabHost.addTab(tabHost.newTabSpec("info").setIndicator("信息",getResources().getDrawable(R.drawable.info)).setContent(R.id.tab5));  

  18.    }  

  19. }  


Android TabHost_Android