问题
How do I change the color of the bottom bar for TabWidget? I have successfully changed the tab background color but the bottom bar is still grey/orange and I couldn't find any info in the Android doc and source regarding this. Thanks.
回答1:
I'm guessing that "bottom bar" refers to the optional horizontal line that separates the tabs and the content. Take a look at the various tabStrip attributes described in the TabWidget API doc. You can set different drawables for the left and right parts of the strip.
回答2:
See:
to enable/disable this line:
tabHost.getTabWidget().setStripEnabled(boolean);
to set drawable at left for this line:
tabHost.getTabWidget().setLeftStripDrawable(drawable);
to set resourse at left for this line
tabHost.getTabWidget().setLeftStripDrawable(resId);
to set drawable at right for this line:
tabHost.getTabWidget().setRightStripDrawable(drawable);
to set resourse at right for this line:
tabHost.getTabWidget().setRightStripDrawable(resId);
回答3:
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);
}
}
}
来源:https://stackoverflow.com/questions/6182247/change-android-tabwidget-bottom-bar-color