abHost mTabHost; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //取得TabHost對象 mTabHost = getTabHost(); /* 為TabHost添加標籤 */ //建立一個newTabSpec(newTabSpec) //設定其標籤和表徵圖(setIndicator) //設定內容(setContent) mTabHost.addTab(mTabHost.newTabSpec("tab_1") .setIndicator("TAB 1",getResources().getDrawable(R.drawable.img1)) .setContent(R.id.textview1)); mTabHost.addTab(mTabHost.newTabSpec("tab_2") .setIndicator("TAB 2",getResources().getDrawable(R.drawable.img2)) .setContent(R.id.textview2)); mTabHost.addTab(mTabHost.newTabSpec("tab_3") .setIndicator("TAB 3",getResources().getDrawable(R.drawable.img3)) .setContent(R.id.textview3)); //設定TabHost的背景顏色 mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150)); //設定TabHost的背景圖片資源 mTabHost.setBackgroundResource(R.drawable.bg0); //設定當前顯示哪一個標籤 mTabHost.setCurrentTab(0); //標籤切換事件處理,setOnTabChangedListener mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { } }); }}轉入核心問題吧。1.將TabHost的標題的表徵圖改變吧。首先我們應該擷取到布局View,再擷取對應的控制項,表徵圖應該是ImageView,文本應該是TextView。代碼如下:View mView = mTabHost.getTabWidget().getChildAt(0);//0是代表第一個TabImageView imageView = (ImageView)mView.findViewById(Android.R.id.icon);//擷取控制項imageViewimageView .setImageDrawable(getResources().getDrawable(R.drawable.img3)); //改變我們需要的表徵圖imageView = (ImageView)mTabHost.getTabWidget().getChildAt(1).findViewById(Android.R.id.icon);imageView .setImageDrawable(getResources().getDrawable(R.drawable.img2));imageView = (ImageView)mTabHost.getTabWidget().getChildAt(2).findViewById(Android.R.id.icon);imageView .setImageDrawable(getResources().getDrawable(R.drawable.img1));2.將TabHost的標題改變吧。TextView textview = (TextView)mTabHost.getTabWidget().getChildAt(0).findViewById(Android.R.id.title);textview.setTextSize(1);textview = (TextView)mTabHost.getTabWidget().getChildAt(1).findViewById(Android.R.id.title);textview.setTextSize(2);textview = (TextView)mTabHost.getTabWidget().getChildAt(2).findViewById(Android.R.id.title);textview.setTextSize(3);其實擷取了View,我們還可以再此基礎上可以設定標題的顏色啊,字型啊,字型大小等等哦。