Search code examples
androidfragmentpageradapterandroiddesignsupportandroid-tablayout

Design Support TabLayout


I'm playing around with the Design Support Library TabLayout. My problem is that the title of one of the tabs is too long and so, it is drawn on 2 lines instead of 1. I'm wondering if there's a way scale the title text size to ensure that all titles are drawn on 1 line.

Here's a screenshot to better explain my problem:enter image description here

In case the details are important, I'm using Design Support TabLayout, a ViewPager and a FragmentPagerAdapter to populate my tabs.

Thanks in advance!


Solution

  • You can change font size or another params of tabLayout in styles.xml. For example:

    <style name="Base.Widget.Design.TabLayout" parent="android:Widget">
            <item name="tabMaxWidth">@dimen/tab_max_width</item>
            <item name="tabIndicatorColor">?attr/colorAccent</item>
            <item name="tabIndicatorHeight">2dp</item>
            <item name="tabPaddingStart">12dp</item>
            <item name="tabPaddingEnd">12dp</item>
            <item name="tabBackground">?attr/selectableItemBackground</item>
            <item name="tabTextAppearance">@style/AppTheme.TextAppearance.Design.Tab</item>
            <item name="tabSelectedTextColor">?android:textColorPrimary</item>
        </style>
    
        <style name="AppTheme.TextAppearance.Design.Tab" parent="TextAppearance.AppCompat.Button">
            <item name="android:textSize">12sp</item>
            <item name="android:textColor">?android:textColorSecondary</item>
            <item name="textAllCaps">true</item>
        </style>