3

私のプロジェクトでは、フォント android: fontFamily = "sans-serif-light" を使用しており、適切に動作しています。

ライブラリのviewpagerindicatorも使用しています。viewpagerindicator にもフォント android: fontFamily = "sans-serif-light" を使いたいのですが、やり方がわかりません

android:fontFamily = "sans-serif-light"inと in styleを使用してみまし<com.viewpagerindicator.TitlePageIndicator ...たが、成功しませんでした。

私も試しました:

PageIndicator mIndicator = (TitlePageIndicator) findViewById (R.id.indicator);
Typeface myTypeface = Typeface.createFromAsset (getAssets (), "fonts / Roboto-Light.ttf");
mIndicator.setTypeface (myTypeface);

しかし、これは機能しません..

助けていただければ幸いです。

感謝と敬意

4

3 に答える 3

10

私が誤解していなければ、ビュー ページャー インジケーターのタイトル フォントを変更したいでしょう。

それを達成するためにライブラリを変更しました.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");
于 2013-07-19T13:40:39.793 に答える
0

より OOD の実装は、新しいインターフェイスを作成してライブラリを変更することです。

public interface FontPagerAdapter {
/**
 * Get the fonts to set.
 */
Typeface getCustomFont();}

クラス TabPageIndicator.java に新しいプロパティを追加します。

private Typeface customTypeFace;

これは、次のように宣言することにより、notifyDataSetChanged() メソッドで設定されます。

if (adapter instanceof FontPagerAdapter) {
        FontPagerAdapter fontAdapter = (FontPagerAdapter)adapter;
        customTypeFace = fontAdapter.getCustomFont();
    }

後で addTab メソッドで次のようにプログラムで設定してフォントを変更します。

if (customTypeFace != null) {
   tabView.setTypeface(customTypeFace);
}

最後に、ライブラリを使用するアダプターで、このインターフェイスを実装し、メソッドをオーバーライドする必要があります。

@Override
public Typeface getCustomFont() {
    Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/PoetsenOne-Regular.ttf");
    return font;
}
于 2014-07-09T20:33:46.797 に答える