Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabLayout set spacing or margin each tab

I want to set margin in between each tab. Like in PagerTabStrip which has setTextSpacing(int textSpacing) to make text spacing between tab. Can TabLayout do that?

like image 450
Akirayjin Avatar asked Sep 15 '15 07:09

Akirayjin


People also ask

How do you change the typeface of a selected tab of a TabLayout?

You can change the font family for selected/unselected tab only programmatically. You can listen which Tab is selected and unselected with TabLayout. OnTabSelectedListener and on onTabSelected(TabLayout. Tab tab) callback you can change the Typeface for the selected Tab and on onTabUnselected(TabLayout.

How do I set ViewPager to TabLayout?

Android ViewPager ViewPager with TabLayout A TabLayout can be used for easier navigation. You can set the tabs for each fragment in your adapter by using TabLayout. newTab() method but there is another more convenient and easier method for this task which is TabLayout. setupWithViewPager() .


2 Answers

Been fighting this problem for a while too, found the solution on this thread : Android Design Support Library TabLayout using custom tabs layout but layout wrapping the tabs

<!-- Add the padding to tabPaddingStart and/or tabPaddingEnd --> <android.support.design.widget.TabLayout         android:id="@+id/tabLayout"         android:layout_width="match_parent"         android:layout_height="@dimen/tab_layout_height"         app:tabPaddingStart="10dp"         app:tabPaddingEnd="10dp"> 
like image 142
Sammy Patenotte Avatar answered Sep 17 '22 07:09

Sammy Patenotte


You can use tabMinWidth attribute. like this.

<android.support.design.widget.TabLayout     android:id="@+id/tabs"     android:layout_width="match_parent"     android:layout_height="44dp"     app:tabIndicatorColor="@color/default_enable"     app:tabTextColor="@color/font_default_03"     app:tabSelectedTextColor="@color/default_enable"     app:tabMinWidth="50dp"     android:clipToPadding="false"     android:paddingLeft="4dp"     android:paddingRight="4dp" /> 
like image 39
권홍재 Avatar answered Sep 20 '22 07:09

권홍재