Android:在PagerTitleStrip中更改字体

问题描述:

有谁知道如何做到这一点? PagerTitleStrip类没有.setTypeface方法或任何类型的东西,所以我有点难住。Android:在PagerTitleStrip中更改字体

我发现的另一个回应建议: You are probably best served copying the PagerTitleStrip code (in your SDK or available online), refactor your fork into your own package, and modify it to suit.但我不知道如何去做这件事。

任何帮助将不胜感激。

+0

“但我不知道如何去做这件事 - ”你有什么困难与“这个”的一部分? – CommonsWare

+0

“重构你的叉子到你自己的包”大部分是这个部分。我已将PagerTitleStrip复制到我自己的文件中,以便我可以编辑。 – Marche101

+1

在这种情况下,“重构”意味着“将代码从'android.support.v4.view'移动到您自己的Java包中。 – CommonsWare

我刚才复制的源出AOSP的,使我自己怎么喜欢:

该文件可以在Android的SDK /演员/安卓/支持/ V4/src目录/ JAVA /安卓/支持被发现/v4/view/PagerTitleStrip.java

+0

当我尝试这样做时,出现很多错误,例如”implements ViewPager.Decor “它说”ViewPager.Decor类型不可见“,还有很多这种类型的错误 – Marche101

+2

您需要将它放在包android.support.v4.view中,并且可能会更改类的名称。 –

+0

啊,太棒了,非常感谢!你不知道我一直在尝试这么做多久。 – Marche101

您不必复制源 - 只是子类。看到我的答案在:how to change the font of a pagertitlestrip

如果它是一个自定义字体把它放在资产文件夹,并像这样改变它。

PagerTitleStrip _Title = (PagerTitleStrip)rootView.findViewById(R.id.__Weekly_pager_title_strip); 
    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "Your font.ttf"); 
    for (int counter = 0 ; counter<_Title.getChildCount(); counter++) { 

     if (_Title.getChildAt(counter) instanceof TextView) { 
      ((TextView)_Title.getChildAt(counter)).setTypeface(font); 
      ((TextView)_Title.getChildAt(counter)).setTextSize(25); 
     } 

    }