Search code examples
javaandroidandroid-tablayout

How to change font size in TabLayout?


In my application I want to use TabLayout and I use this library:

https://github.com/LiushuiXiaoxia/TabLayoutPlus

However, the text size is big and I want to change it. For this I set custom style in style.xml, but it does not change the text size.

XML Code:

<cn.mycommons.tablayoutplus.library.TabLayoutPlus
    android:id="@+id/fullSearch_tabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/fullSearch_toolbar"
    android:background="@color/colorPrimary"
    android:paddingBottom="@dimen/size2"
    android:paddingLeft="@dimen/size2"
    android:paddingRight="@dimen/size2"
    app:tabIndicatorColor="@color/whiteMe"
    app:tabSelectedTextColor="@color/whiteMe"
    app:tabTextAppearance="@style/allCapsTabLayout_search"
    app:tabTextColor="@color/unSelectTab" />


<style name="allCapsTabLayout_search" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textSize">@dimen/font5</item>
</style>

How can I change text size?


Solution

  • Go to

    1> Your Library Module

    2> open a file "tablayoutplus_custom_view.xml"

    3> set android:textSize="20sp" into "android:id="@+id/tvTabText""

    OR

    Set Programatically in Library module in "BadgedTabCustomView.java":

      tvTabText.setTextSize(20);
    

    Hope this helps you now.