问题
Is the android:divider attribute under the TabWidget working? I tried the Tab Layout tutorial from android just to test (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and set the android:divider to some image (for now I used the android vertical scrollbar as the drawable to really emphasize if its getting picked up (copied it from frameworks), but when I ran it on the emulator, it doesn't appear to be working. According to the docs, the TabWidget does seem to support this attribute: "Drawable used to draw the divider between tabs."
Can anyone help? I am using a nine-patched drawable as my divider image drawable.
MB
回答1:
It doesn't look like the divider
attribute is available anymore for TabWidget
. One way to add a custom divider is to set it programmatically:
mTabHost.getTabWidget().setDividerDrawable(R.drawable.divider_vertical_dark);
Make sure however, you call this before you set the content of the tabs. It would crash on me if I called it after.
回答2:
I had the problem in ICS, where divider was visible. None of the solutions worked except for the following.
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:fadingEdge="none"
android:showDividers="none" >
</TabWidget>
Key line was android:showDividers="none"
回答3:
I had this issue and solved it with the following code
tabHost1.getTabWidget().setDividerDrawable(R.drawable.example1);
if(Build.VERSION.SDK_INT >= 11)
tabHost1.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE);
For api levels below 11, it worked with the first line. For 11 and higher I included this to get this working. setShowDividers is added in linearlayout from api level 11. Hope this helps someone
回答4:
Having the same issue myself. I only see the problem in Ice Cream Sandwich (ICS / 4.0.x). In android 1.6 - 2.3.4 there is no issue, dividers show up properly when setting a drawable in code, or in the xml layout.
I've tried just about everything I can think of to fix it but nothing works, including Josh's answer above :( though I have noticed that when setting any drawable as the divider, it will take up the space between tabs as if there was a drawable there, but it's just not visible.
Hopefully that gives someone else a hint as to what could be happening..?
回答5:
I removed divider line from tabbar with use of below magical lines.
mTabHost.getTabWidget().setDividerDrawable(null);
OR
mTabHost.getTabWidget().setDividerDrawable(R.Color.transperant);
来源:https://stackoverflow.com/questions/3705346/dividers-between-tabwidgets