当我单击标签栏以更改选项卡时,未调用我的方法onTabChanged()
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);
}
}
请帮助我,我想在标签选择发生变化时改变颜色。
答案 0 :(得分:2)
您需要将 OnTabChangeListener 设置为 TabHost ,如下所示:
//set tab change listener
tabHost.setOnTabChangedListener(this);
//where 'this' is a reference to your activity ZoobuzzActivity