2012-03-29 36 views
0
當我點擊標籤欄更改標籤

onTabChanged方法不inwalking,

public class ZoobuzzActivity extends TabActivity implements OnTabChangeListener { 
/** Called when the activity is first created. */ 
TabHost tabHost; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.first_tab); 
} 

public void onTabChanged(String tabId) { 

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.RED); 
    } 
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.GREEN); 
    } 
} 

請幫助我,我想改變顏色,當標籤選擇改變

我的方法onTabChanged()沒有被調用。

回答

2

您需要設置OnTabChangeListener爲下方的TabHost

//set tab change listener 
tabHost.setOnTabChangedListener(this); 

//where 'this' is a reference to your activity ZoobuzzActivity