2013-08-07 39 views
-2

我想下面的代碼,但不能正常工作如何在android中將顏色設置爲選項卡?

public static void setTabColor(TabHost tabhost) { 
    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
    { 
     tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); //unselected 
    } 
    tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#0000FF")); // selected 
} 

我想改變我的選項卡的默認顏色。

預先感謝

+0

http://stackoverflow.com/questions/5577688/android-change-tab-text-color-programmatically ?rq = 1 – Ilan

+0

此代碼給出錯誤 –

回答

0
TabHost tabhost = getTabHost(); 
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
{ 
    RelativeLayout tv = (RelativeLayout) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); 
    tv.setBackgroungColor(.....); 
} 

只要使用這樣的...希望它的工作原理

+0

我想要背景顏色不是文字顏色 –

+0

@ Kiran Mane你剛剛使用了相對佈局ID從那裏 – FarhaSameer786

+0

@KiranMane它的工作與否? – FarhaSameer786

相關問題