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

對Android中Tab的使用總結

對Android中Tab的使用總結
  1. package com.eric.LinearLayout;   
  2.   
  3. import android.app.TabActivity;   
  4. import android.content.Intent;   
  5. import android.os.Bundle;   
  6. import android.view.LayoutInflater;   
  7. import android.widget.TabHost;   
  8. import android.widget.TextView;   
  9. import com.eric.R;   
  10.   
  11. /**  
  12.  * 對tab的選擇按鈕的測試及終結 創建人: 創建時間:2011-6-24  
  13.  *   
  14.  * @author chenhaodejia  
  15.  *   
  16.  */  
  17. public class HelloTabWidget extends TabActivity {   
  18.   
  19.     // TabActivity   
  20.     @Override  
  21.     public void onCreate(Bundle savedInstanceState) {   
  22.         super.onCreate(savedInstanceState);   
  23.   
  24.         /*  
  25.          * TabHost tabHost = getTabHost();  
  26.          * LayoutInflater.from(this).inflate(R.layout.tab_1,  
  27.          * tabHost.getTabContentView(), true);  
  28.          * tabHost.addTab(tabHost.newTabSpec(  
  29.          * "tab1").setIndicator("tab1").setContent(R.id.textview1));  
  30.          *   
  31.          * //添加tab  
  32.          * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB 2"  
  33.          * ).setContent(R.id.textview1));  
  34.          * tabHost.addTab(tabHost.newTabSpec("tab_test3"  
  35.          * ).setIndicator("TAB 3").setContent(R.id.textview2));  
  36.          * tabHost.addTab(tabHost  
  37.          * .newTabSpec("tab_test4").setIndicator("TAB 4").setContent  
  38.          * (R.id.textview3)); tabHost.setCurrentTab(1);  
  39.          * //默認需要選中那一個tab,就填寫一個tab的index,這裡的tab的index是以o開始的  
  40.          */  
  41.         /*  
  42.          * //給tab添加圖片 TabHost tabHost = getTabHost();  
  43.          * LayoutInflater.from(this).inflate(R.layout.tab_1,  
  44.          * tabHost.getTabContentView(), true);  
  45.          * tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1",  
  46.          * getResources  
  47.          * ().getDrawable(R.drawable.baob1)).setContent(R.id.textview1));  
  48.          * tabHost  
  49.          * .addTab(tabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent  
  50.          * (R.id.textview2));  
  51.          * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator  
  52.          * ("TAB 2").setContent(R.id.textview3)); tabHost.setCurrentTab(0);  
  53.          */  
  54.   
  55.         /*  
  56.          * //給tab賦值窗體,在點擊tab的時候,在下面顯示一個Form,進行需要的處理 final TabHost tabHost =  
  57.          * getTabHost(); LayoutInflater.from(this).inflate(R.layout.tab_1,  
  58.          * tabHost.getTabContentView(), true);  
  59.          * tabHost.addTab(tabHost.newTabSpec(  
  60.          * "tab1").setIndicator("list").setContent(new Intent(this,  
  61.          * FormStuff.class)));  
  62.          * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator  
  63.          * ("TAB 2").setContent(new Intent(this, TableLayout.class)));  
  64.          * tabHost.addTab  
  65.          * (tabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent  
  66.          * (R.id.textview2));  
  67.          * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator  
  68.          * ("TAB 2").setContent(R.id.textview3)); tabHost.setCurrentTab(1);  
  69.          */  
  70.   
  71.         // 對上面三種tab形式的整合   
  72.         TabHost tabHost = getTabHost();   
  73.         LayoutInflater.from(this).inflate(R.layout.tab_1,   
  74.                 tabHost.getTabContentView(), true);   
  75.         tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1",   
  76.                 getResources().getDrawable(R.drawable.baob1)).setContent(   
  77.                 new Intent(this, TableLayout.class)));   
  78.         tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB 2",   
  79.                 getResources().getDrawable(R.drawable.baob2)).setContent(   
  80.                 new Intent(this, FormStuff.class)));   
  81.         tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator("TAB 3",   
  82.                 getResources().getDrawable(R.drawable.baob3)).setContent(   
  83.                 R.id.textview2));   
  84.         tabHost.addTab(tabHost.newTabSpec("tab_test4").setIndicator("TAB 4",   
  85.                 getResources().getDrawable(R.drawable.baob4)).setContent(   
  86.                 R.id.textview3));   
  87.         tabHost.setCurrentTab(0);   
  88.     }   
  89. }  
Copyright © Linux教程網 All Rights Reserved