1

I've created a tablayout class to change fonts. Unfortunately, the font does not change.

Where's the problem?

Assets folder path font\

public class Tablayout_customfonts extends TabLayout {

    private Typeface typeface;

    public Tablayout_customfonts(Context context) {
        super(context);
        init();
    }

    public Tablayout_customfonts(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public Tablayout_customfonts(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
       typeface = Typeface.createFromAsset(getContext().getAssets(), "font/BYekan.ttf");    }

    @Override
    public void addTab(Tab tab) {
        super.addTab(tab);

        ViewGroup mainView = (ViewGroup) getChildAt(0);
        ViewGroup tabView = (ViewGroup) mainView.getChildAt(tab.getPosition());

        int tabChildCount = tabView.getChildCount();
        for (int i = 0; i < tabChildCount; i++) {
            View tabViewChild = tabView.getChildAt(i);
            if (tabViewChild instanceof TextView) {
                ((TextView) tabViewChild).setTypeface(typeface, Typeface.NORMAL);
            }
        }
    }

}
Pang
  • 9,564
  • 146
  • 81
  • 122
  • Why do you use Typeface.NORMAL in your for loop? Set Typeface only :((TextView) tabViewChild).setTypeface(typeface); For more information please refer this link : https://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android – AndiM Sep 02 '17 at 03:57

0 Answers0