歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android TabHost風格

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.   
  12.             <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">  
  13.                 <ImageView android:id="@+id/imageView2" android:src="@drawable/intnet" android:layout_width="match_parent" android:layout_height="match_parent"></ImageView>  
  14.             </LinearLayout>  
  15.   
  16.             <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">  
  17.                             <ImageView android:id="@+id/imageView4" android:src="@drawable/reresh" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  
  18.             </LinearLayout>  
  19.   
  20.             <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">  
  21.                             <ImageView android:id="@+id/imageView5" android:src="@drawable/search" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  
  22.             </LinearLayout>  
  23.   
  24.              <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab4">  
  25.                              <ImageView android:id="@+id/imageView3" android:src="@drawable/picture" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  
  26.              </LinearLayout>  
  27.   
  28.             <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab5">  
  29.                             <ImageView android:id="@+id/imageView1" android:src="@drawable/info" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  
  30.             </LinearLayout>  
  31.   
  32.         </FrameLayout>  
  33.     </LinearLayout>  
  34. </TabHost>  
  35. </LinearLayout>  
Activity
  1. package rw.Tab;  
  2.   
  3. import android.app.TabActivity;  
  4. import android.os.Bundle;  
  5. import android.widget.TabHost;  
  6.   
  7. public class Tabhost02Activity extends TabActivity {  
  8.     /** Called when the activity is first created. */  
  9.      private TabHost tabHost;  
  10.     @Override  
  11.     public void onCreate(Bundle savedInstanceState) {  
  12.         super.onCreate(savedInstanceState);  
  13.         setContentView(R.layout.main);  
  14.         tabHost=getTabHost();  
  15.         tabHost.addTab(tabHost.newTabSpec("network").setIndicator("流量",getResources().getDrawable(R.drawable.intnet)).setContent(R.id.tab1));  
  16.         tabHost.addTab(tabHost.newTabSpec("refesh").setIndicator("刷新",getResources().getDrawable(R.drawable.reresh)).setContent(R.id.tab2));  
  17.         tabHost.addTab(tabHost.newTabSpec("search").setIndicator("搜索",getResources().getDrawable(R.drawable.search)).setContent(R.id.tab3));  
  18.         tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("圖片",getResources().getDrawable(R.drawable.picture)).setContent(R.id.tab4));  
  19.         tabHost.addTab(tabHost.newTabSpec("info").setIndicator("信息",getResources().getDrawable(R.drawable.info)).setContent(R.id.tab5));  
  20.           
  21.     }  
  22. }  
Copyright © Linux教程網 All Rights Reserved