dividers between TabWidgets

23,764

Solution 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.

Solution 2

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

Solution 3

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"

Solution 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..?

Share:
23,764
mbethdev
Author by

mbethdev

Updated on September 09, 2020

Comments

  • mbethdev
    mbethdev over 3 years

    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

  • danwilkie
    danwilkie almost 11 years
    Thanks a lot for this! For me this wouldn't compile as I compile against an older API level, but it works like a charm when modified to use reflection to invoke the method.
  • Dharmendra
    Dharmendra almost 10 years
    Your line "You call this before you set the content of the tabs" is mind blowing. fixed my problem :)