Reputation: 1662
divider in tabWidget is working fine but when background of tab widget is set like
tabHost.getTabWidget().getChildTabViewAt(tabId).setBackgroundResource(R.drawable.tab_indicator);
problem is how to set divider in tab widget after setting background though i used
tabhost.getTabWidget().setDividerDrawable(R.drawable.tab_widget_divider);
is does not work for multiple tab.
Upvotes: 1
Views: 5197
Reputation: 951
There may be multiple reasons for the dividers not showing up...
1. setDividerDrawable() must be used before you add the tabs to the tabHost to work.
2. By default there's are -2(left), -2(right) margins set to each tabindicator's View...
By default the system is using 9-patch drawables for tabWidget backgrounds with at least 2 pixels left transparent(or semi-transparent for shadow-effect) to the left and the right side.
1. demonstration
2. Stock 9-path drawables for tab widget background. You can use these for experimenting
If you don't wan't to use 9-path drawables... you can set the margins to 0 to prevent the tab views overlapping your divider. Here's the code:
View v;
int count = tw.getTabCount();
for (int i = 0; i < count; i++) {
v = tw.getChildTabViewAt(i);
v.setBackgroundResource(R.drawable.bg_tab);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
params.setMargins(0, 0, 0, 0);
}
Upvotes: 14