Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to add vertical line between each tab in TabLayout

Tags:

android

The TabLayout is quite userful building a sliding tab for viewpager, except there is no way you can add vertical line between tabs just like TabHost in code or xml as far as I know, so is there other way to do so with ease?

like image 303
KNOX.C Avatar asked Sep 25 '15 06:09

KNOX.C


People also ask

How do I use TabLayout with ViewPager?

Tab layout are visible below toolbar with View pager, used to create swipeable views . Tabs are designed to work with fragments. Use them to swipe fragments in view pager.


1 Answers

TabLayout is actually a horizontal scrollable LinearLayout.

Just use following code to add dividers:

    LinearLayout linearLayout = (LinearLayout)tabLayout.getChildAt(0);
    linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(Color.GRAY);
    drawable.setSize(1, 1);
    linearLayout.setDividerPadding(10);
    linearLayout.setDividerDrawable(drawable);
like image 199
kim Avatar answered Oct 10 '22 23:10

kim