Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom font in viewpagerindicator

In my project I am using the font android: fontFamily = "sans-serif-light", and working properly.

I am also using the library viewpagerindicator. I want to use the font android: fontFamily = "sans-serif-light" also in the viewpagerindicator, but can not find how to do it

I've tried using android:fontFamily = "sans-serif-light" in <com.viewpagerindicator.TitlePageIndicator ... and in style, but without success.

I have also tried:

PageIndicator mIndicator = (TitlePageIndicator) findViewById (R.id.indicator);
Typeface myTypeface = Typeface.createFromAsset (getAssets (), "fonts / Roboto-Light.ttf");
mIndicator.setTypeface (myTypeface);

but this does not work ..

I appreciate any help.

Thanks and regards

like image 973
Sergio76 Avatar asked May 21 '26 23:05

Sergio76


1 Answers

If I don't get you wrong, you want to change titles font in view pager indicator,

I changed the library to achieve that, for TabPageIndicator custome typeface I added this for TabPageIndicator.java

private Typeface                       mTypeface;
public void setTypeFace(Typeface tf) {
    this.mTypeface = tf;
    }

and then change addTab function to this:

    private void addTab(int index, CharSequence text, int iconResId) {
final TabView tabView = new TabView(getContext());
tabView.mIndex = index;
tabView.setFocusable(true);
tabView.setOnClickListener(mTabClickListener);
tabView.setText(text);


**if (mTypeface != null) {
    tabView.setTypeface(mTypeface);
}**


if (iconResId != 0) {
    tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
}

mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

now you should just setTypeFace on your tabpagerindicator, like this:

mTabPageIndicator = (TabPageIndicator) findViewById(R.id.tab_page_indicator);
mTabPageIndicator.setTypeFace(Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/custome_font.ttf");
like image 89
Sadegh Avatar answered May 23 '26 12:05

Sadegh