Reputation: 3813
I need change indicator border line for my tabs, so i do following:
//set custom background for each tab
View v;
int count = tabWidget.getTabCount();
for (int i = 0; i < count; i++) {
v = tabWidget.getChildTabViewAt(i);
v.setBackgroundResource(R.drawable.tab_selector_main);
v.setPadding(0, 0, 0, 0);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
params.setMargins(-Utils.dpToPx(3, this), 0, -Utils.dpToPx(3, this), 0);
}
here is my drawable, in which i set 9-patches
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_green" />
<item android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_selected_unpressed_green" />
<item android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed" />
<item android:drawable="@drawable/tab_unselected_unpressed"/>
</selector>
The problem is, that after that, the default divider is gone, and there are some gap between tabs. How can i enable default divider or set mine? I google a lot, and seems nothing help me. I use 4.0.4 version and fragmenttabhost with tabwidget. Thanks.
UPD: I found what problem is in my 9-patches. I change color to transparent, except bottom indicator line and setDividerDrawable start working. but still there are gap between bottom indicator line.
Upvotes: 0
Views: 403
Reputation: 3456
You can use android:showDividers="none" in your XML layout.
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showDividers="none" />
Upvotes: 2