How c开发者_运维技巧an i implement this in a TabActivity?
That looks much like the standard TabHost ( http://developer.android.com/resources/tutorials/views/hello-tabwidget.html ) and an implementation of OnTabChangedListener.
Add the listener to the instance of your TabHost:
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
setTabHostColors();
}});
Handle changing the background color:
private void setTabHostColors() {
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.rgb(0, 0, 0)); //unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.rgb(50, 120, 160)); // selected
}
And then finally it obviously has a nice little background picture, not sure where to get that one I'm afraid.
Here is a small sample project to customize your tabs: http://code.google.com/p/android-custom-tabs/
精彩评论