Home > Net >  How to change font size in Material Design TabLayout android?
How to change font size in Material Design TabLayout android?

Time:02-10

I have been trying to explore online to set my font size for TabLayout TabItems But none of them seems to be working for me. This is what I tried referring last link

below are the things which I have implemented so far, Not sure why it's not picking textSize from style.

in xml:

<com.google.android.material.tabs.TabLayout
                android:id="@ id/tabLayoutForgot"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/header_height"
                app:layout_constraintTop_toBottomOf="@ id/imageViewLogo"
                app:tabIndicatorColor="@color/text_color"
                app:tabSelectedTextColor="@color/text_color"
                app:tabGravity="fill"
                app:tabTextAppearance="@style/MyCustomTabLayout"
                app:tabMode="fixed"
                app:tabIndicatorFullWidth="false"
                app:tabTextColor="@color/text_color" />

in themes.xml:

<style name="MyCustomTabLayout" parent="@android:style/TextAppearance.Widget.TabWidget">
        <item name="textAllCaps">false</item>
        <item name="android:textSize">20sp</item>
        <item name="android:fontFamily">@font/roboto_medium</item>
        <item name="android:textColor">@color/text_color</item>
    </style>

this does everything else like textAllCaps and fontFamily but doesn't seems to take textSize.

Appreciate any help.

CodePudding user response:

You should inherit your style from TextAppearance.Design.Tab First make a style,

<style name="MyStyle" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">16sp</item>
</style>

Then use it in your Tablayout like this,

<android.support.design.widget.TabLayout
            app:tabTextAppearance="@style/MyStyle"
            ...
            />

hope it will work

  •  Tags:  
  • Related