private void initTabs() { TabPagerAdapter adapter = new TabPagerAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); tabLayout.setupWithViewPager(pager); //tabLayout it doesn't respond to style attribute 'tabTextAppearance' so we have to use customview for (int i = 0; i < adapter.getCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab != null) { tab.setCustomView(R.layout.tab_text); tab.setText(adapter.getPageTitle(i)); } } }
res/layout/tab_text.xml
<?xml version="1.0" encoding="utf-8"?> <!-- needs this container to work with the Tablayout --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <TextView android:id="@android:id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:gravity="center" android:maxLines="2" app:fontPath="**your custom font here**" tools:ignore="MissingPrefix" tools:text="User Profile" /> </FrameLayout>
References
https://github.com/chrisjenx/Calligraphy/issues/180