在我的项目中,我使用字体 android: fontFamily = "sans-serif-light",并且工作正常。
我也在使用库 viewpagerindicator。我也想在 viewpagerindicator 中使用字体 android: fontFamily = "sans-serif-light",但找不到如何操作
我试过使用 android:fontFamily = "sans-serif-light"
在<com.viewpagerindicator.TitlePageIndicator ...
和风格,但没有成功。
我也试过:
PageIndicator mIndicator = (TitlePageIndicator) findViewById (R.id.indicator);
Typeface myTypeface = Typeface.createFromAsset (getAssets (), "fonts / Roboto-Light.ttf");
mIndicator.setTypeface (myTypeface);
但这行不通..
感谢任何帮助。
感谢和问候
最佳答案
如果我没有误会你的意思,你想在 View 寻呼指示器中更改标题字体,
我改变了图书馆来实现这一点, 对于 TabPageIndicator 自定义字体,我为 TabPageIndicator.java 添加了这个
private Typeface mTypeface;
public void setTypeFace(Typeface tf) {
this.mTypeface = tf;
}
然后将 addTab 函数更改为:
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));
}
现在你应该在你的 tabpagerindicator 上设置 TypeFace,像这样:
mTabPageIndicator = (TabPageIndicator) findViewById(R.id.tab_page_indicator);
mTabPageIndicator.setTypeFace(Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/custome_font.ttf");
关于android - 在 viewpagerindicator 中使用自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464318/