How can i use custom font for Tablayout class belonging to android.support.design.widget package? I'm using it to implement Quick Return view functionality.
Tabs are created using the newTab() method of TabLayout class. The title and icon of Tabs are set through setText(int) and setIcon(int) methods of TabListener interface respectively. Tabs of layout are attached over TabLayout using the method addTab(Tab) method.
com.google.android.material.tabs.TabLayout. TabLayout provides a horizontal layout to display tabs.
As of 23.2.0, setTabsFromPagerAdapter has been deprecated, however using a modified version of Andreyua's answer you can use setupWithViewPager instead.
@Override
public void setupWithViewPager(ViewPager viewPager)
{
super.setupWithViewPager(viewPager);
if (mTypeface != null)
{
this.removeAllTabs();
ViewGroup slidingTabStrip = (ViewGroup) getChildAt(0);
PagerAdapter adapter = viewPager.getAdapter();
for (int i = 0, count = adapter.getCount(); i < count; i++)
{
Tab tab = this.newTab();
this.addTab(tab.setText(adapter.getPageTitle(i)));
AppCompatTextView view = (AppCompatTextView) ((ViewGroup) slidingTabStrip.getChildAt(i)).getChildAt(1);
view.setTypeface(mTypeface, Typeface.NORMAL);
}
}
}
All credit goes to Andreyua for their original code snippet with a minor modification.
Unfortunately, I don't have enough reputation to make comments or I would have responded directly :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With