我正在使用PagerTabStrip它ViewPager来显示每个页面的标题.这是我的XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#a4c639"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我想将textStyle设置为粗体,PagerTabStrip如下所示:
android:textStyle="bold".但这是不可能的PagerTabStrip.好像它只有textcolor文本属性.我可以将样式设置为粗体的方式是什么?
在我的应用程序中,我正在使用带有PagerTabStrip的ViewPager,我需要将自定义字体设置为我的小部件.要为a Button或a 设置字体,TextView我只需扩展类并设置字体.
public class MyButton extends Button {
public MyButton(Context context) {
super(context);
initCustomFont();
}
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
initCustomFont();
}
public MyButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initCustomFont();
}
private void initCustomFont() {
if(!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/boton_regular.ttf");
setTypeface(tf);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不能用这种方法PagerTabStrip.有没有其他方法来设置可以使用的字体PagerTabStrip?