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.
但我不知道如何去做这件事。
任何帮助将不胜感激。
答
答
如果它是一个自定义字体把它放在资产文件夹,并像这样改变它。
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);
}
}
“但我不知道如何去做这件事 - ”你有什么困难与“这个”的一部分? – CommonsWare
“重构你的叉子到你自己的包”大部分是这个部分。我已将PagerTitleStrip复制到我自己的文件中,以便我可以编辑。 – Marche101
在这种情况下,“重构”意味着“将代码从'android.support.v4.view'移动到您自己的Java包中。 – CommonsWare