TabPageIndicator Text Font

前端 未结 3 1706
故里飘歌
故里飘歌 2021-01-07 02:51

I\'m using ViewPagerIndicator, and haven\'t had any luck, so I\'ll ask here. Is there a way to change the font for the Tabs in a TabPageIndicator?

3条回答
  •  长情又很酷
    2021-01-07 03:35

    So I've kind of brute forced my way into making it work, using a library called Oak (Where the TextViewWithFont is), and passing the PagerIndicator into this method:

    private static void changeFonts(ViewGroup root, Activity a, String typeface) {
        Typeface tf = TextViewWithFont.getStaticTypeFace(a, typeface);
    
        for (int i = 0; i < root.getChildCount(); i++) {
            View v = root.getChildAt(i);
            if (v instanceof TextView) {
                ((TextView) v).setTypeface(tf);
            } else if (v instanceof ViewGroup) {
                changeFonts((ViewGroup) v, a, typeface);
            }
        }
    }
    public static void setTabPageIndicatorFont(ViewGroup root, Activity a) {
        changeFonts(root, a, "DINCondBold.otf");
    }
    

    Oak if anyones interested: http://willowtreeapps.github.com/OAK/

    If anyone has a better way to go about it, I'd love to get a second opinion.

提交回复
热议问题