问题描述
在我的项目,我使用的字体的android:fontFamily中=无衬线光,并正常工作
。我也使用的库viewpagerindicator。我想使用的字体的android:fontFamily中=无衬线光也在viewpagerindicator,却找不到怎么办呢 P>
我试过使用的android:fontFamily中=无衬线光
在< com.viewpagerindicator.TitlePageIndicator ...
和风格,但都没有成功。
我也尝试:
PageIndicator mIndicator =(TitlePageIndicator)findViewById(R.id.indicator);
字体myTypeface = Typeface.createFromAsset(getAssets(),字体/的Roboto-Light.ttf);
mIndicator.setTypeface(myTypeface);
但是,这并不工作..
我AP preciate任何帮助。
感谢和问候
如果我没有得到你错了,你要更改标题的字体鉴于寻呼机指标,
我改变了图书馆实现这一目标,
对于TabPageIndicator custome字体添加此为TabPageIndicator.java
私人字样mTypeface;
公共无效setTypeFace(TF字样){
this.mTypeface = TF;
}
然后更改addTab功能如下:
私人无效addTab(INT指数,CharSequence的文字,INT iconResId){
最后TabView的TabView的=新TabView的(的getContext());
tabView.mIndex =指数;
tabView.setFocusable(真);
tabView.setOnClickListener(mTabClickListener);
tabView.setText(文本);
**如果(mTypeface!= NULL){
tabView.setTypeface(mTypeface);
} **
如果(iconResId!= 0){
tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId,0,0,0);
}mTabLayout.addView(TabView的,新LinearLayout.LayoutParams(0,MATCH_PARENT,1));
}
现在你应该只setTypeFace您tabpagerindicator,像这样的:
mTabPageIndicator =(TabPageIndicator)findViewById(R.id.tab_page_indicator);
mTabPageIndicator.setTypeFace(Typeface.createFromAsset(getApplicationContext()getAssets(),字体/ custome_font.ttf)。
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
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");
这篇关于在viewpagerindicator使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!