android - 在 viewpagerindicator 中使用自定义字体

标签 android viewpagerindicator custom-font

在我的项目中,我使用字体 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/

相关文章:

android - 如何在滑动刷新android中刷新布局

android - Android 中的触摸或单击事件 ViewPagerIndicator

Android Viewpager 显示错误的页面

android - Android 上的自定义字体会降低性能吗?

android - Android 移动浏览器和混合应用程序不支持自定义古吉拉特语字体 (GopikaTwo)

android - 语法错误,插入 "enum Identifier"以完成 EnumHeaderName

android eclipse 模拟器设备未运行

Android ViewPager2 库抛出 Transactiontoolarge 异常 onpause 事件

java - 重新安装 Eclipse 后无法再构建项目

css - Opera 和 webkit 中自定义字体的底部被截断