歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android TabHost風格

Android TabHost風格

日期:2017/3/1 11:14:57   编辑:Linux編程

Android TabHost風格

main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns: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. <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
  8. <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
  9. <TabWidget android:layout_width="match_parent" android:id="@android:id/tabs" android:layout_height="wrap_content"></TabWidget>
  10. <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
  11. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">
  12. <ImageView android:id="@+id/imageView2" android:src="@drawable/intnet" android:layout_width="match_parent" android:layout_height="match_parent"></ImageView>
  13. </LinearLayout>
  14. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">
  15. <ImageView android:id="@+id/imageView4" android:src="@drawable/reresh" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>
  16. </LinearLayout>
  17. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">
  18. <ImageView android:id="@+id/imageView5" android:src="@drawable/search" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>
  19. </LinearLayout>
  20. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab4">
  21. <ImageView android:id="@+id/imageView3" android:src="@drawable/picture" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>
  22. </LinearLayout>
  23. <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab5">
  24. <ImageView android:id="@+id/imageView1" 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. public class Tabhost02Activity extends TabActivity {
  6. /** Called when the activity is first created. */
  7. private TabHost tabHost;
  8. @Override
  9. public void 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. }
Copyright © Linux教程網 All Rights Reserved