我正在使用带有 PagerTabStrip 的 ViewPager,我需要设置自定义字体(typeface)
,但是 PagerTabStrip 没有.setTypeFace
功能!
这是我的 XML 代码:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pagerTabStrip"
android:layout_gravity="top"
android:background="#FF0000"
android:textColor="#FFFFFF" />
</android.support.v4.view.ViewPager>
根据这个链接,我找到了一个可以解决我的问题的解决方案。
获取 PagerTabStrip 的子视图并检查它是否是 TextView 的实例。如果是,请设置字体:
for (int i = 0; i < pagerTabStrip.getChildCount(); ++i) {
View nextChild = pagerTabStrip.getChildAt(i);
if (nextChild instanceof TextView) {
TextView textViewToConvert = (TextView) nextChild;
textViewToConvert.setTypeface(PUT_TYPEFACE_HERE)
}
}
但我不明白这是什么意思。
我的布局是:
我想将标题选项卡更改为另一种字体样式,如下所示: