4

私のアプリでは、PagerTabStripViewPagerを使用しており、ウィジェットにカスタム フォントを設定する必要があります。Buttonaまたは 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);
        }
    }
}

しかし、私はこの方法をPagerTabStrip. で使用できる書体を設定する別の方法はありPagerTabStripますか?

4

2 に答える 2

20

少し遅れましたが、ここに1つの解決策があります。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)
    }
}
于 2012-11-16T06:53:17.417 に答える
1

PagerTabStripwith Hierarchy View(Eclipseでは、アプリケーションの実行時にHierarchy Viewパースペクティブを開きます)を調べて、その子を検索します。TextView1つは、タブのタイトルを保持するものである必要があります。これTextViewを入手して、書体を設定します。

于 2012-08-13T11:54:35.613 に答える