How to change the font of tabLayout with a custom font / calligraphy

Viewed 9231

I was looking for answers about how I can change the fonts of those tabs in that TabLayout to a custom font.

I tried this but it didnt work

 Typeface hero = Typeface.createFromAsset(getContext().getAssets(),"fonts/Hero Light.otf");

            textViewToConvert.setTypeface(hero);
        }
    }
5 Answers

In your layout

<android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        style="@style/Tab"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        app:tabTextAppearance="@style/MineCustomTabText"/>

and in your style folder

<style name="MineCustomTabText" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">12sp</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:fontFamily">@font/two_light_1</item>
</style>

you can use tabTextAppearance in tablayout in Xml layout

Related