2011-05-31 153 views
2

如何更改TabWidget底部欄的顏色?我已成功更改標籤背景顏色,但底部欄仍然是灰色/橙色,我無法在Android文檔和源代碼中找到任何信息。謝謝。更改Android TabWidget底部欄顏色

+0

看看這個http://joshclemm.com/blog/?p=136 @Kenny馬雲,你會得到一個想法 – Karthik 2011-05-31 03:44:23

+0

我之前看到過這個,只是再次閱讀它,但沒有看到關於底部條的任何內容。我錯過了什麼嗎? – 2011-05-31 22:31:51

回答

0

我猜「底部欄」指的是選項卡和內容分開的可選水平線。看看the TabWidget API doc中描述的各種tabStrip屬性。您可以爲條帶的左側和右側部分設置不同的繪圖。

+0

謝謝。我已經嘗試使用「android:tabStripLeft」和「android:tabStripRight」,但我得到「沒有資源標識符找到屬性'tabStripRight'包'android'」錯誤。任何想法? – 2011-06-01 03:54:24

+0

解決。將我的構建目標從2.1更改爲2.2解決了「找不到資源...」的問題。謝謝! – 2011-06-01 04:02:02

1

參見:

來啓用/禁用這一行: tabHost.getTabWidget().setStripEnabled(boolean);

在左側設置繪製這條線: tabHost.getTabWidget().setLeftStripDrawable(drawable);

設置國土資源在離開該行 tabHost.getTabWidget().setLeftStripDrawable(resId);

設置此行的右側可繪製: tabHost.getTabWidget().setRightStripDrawable(drawable);

以適合這一行設置國土資源: tabHost.getTabWidget().setRightStripDrawable(resId);

0
public void setTabColor(TabHost tabhost) { 
    int totalTabs = tabhost.getTabWidget().getChildCount(); 
    for(int i=0;i<totalTabs;i++) { 
     if(tabHost.getTabWidget().getChildAt(i).isSelected()){ 
      tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_selector); //selector xml for selected 
      tabHost.getTabWidget().setStripEnabled(true); 
      tabHost.getTabWidget().setRightStripDrawable(R.drawable.tab_strip_thin); 
      tabHost.getTabWidget().setLeftStripDrawable(R.drawable.tab_strip_thin); 
     } 
    } 
    }