Typeface xyz=Typeface.createFromAsset(view.getContext().getAssets(),
"fonts/xyz.ttf");
(TextView)abc.setTypeface(xyz);
这就是您创建和设置自定义字体的方式。
我需要设置 a 的字体/字体,但pagertitlestrip
没有.setTypeFace
. pagertitlestrip
有谁知道我该怎么做?
Typeface xyz=Typeface.createFromAsset(view.getContext().getAssets(),
"fonts/xyz.ttf");
(TextView)abc.setTypeface(xyz);
这就是您创建和设置自定义字体的方式。
我需要设置 a 的字体/字体,但pagertitlestrip
没有.setTypeFace
. pagertitlestrip
有谁知道我该怎么做?
PagerTitleStrip
实际上是 extends ,因此您可以将ViewGroup
其子类化并遍历其每个子项以查找需要更改其字体的视图:
public class CustomFontPagerTitleStrip extends PagerTitleStrip {
public CustomFontPagerTitleStrip(Context context) {
super(context);
}
public CustomFontPagerTitleStrip(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/xyz.ttf");
for (int i=0; i<this.getChildCount(); i++) {
if (this.getChildAt(i) instanceof TextView) {
((TextView)this.getChildAt(i)).setTypeface(tf);
}
}
}
}
唯一的缺点是它会阻止 Eclipse 显示您的布局。
如果它是自定义字体,请将其放在资产文件夹中并像这样进行更改。
public class WeeklyFragment extends Fragment{
PagerTitleStrip _Title;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.weekly_fragment, container, false);
_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);
}
}
虽然我认为 ViewPager
支持android:textAppearance
,但您也不能那样设置字体。
您最好复制PagerTitleStrip
代码(在您的 SDK 中或在线提供),将您的 fork 重构到您自己的包中,然后对其进行修改以适应。或者,查看 ViewPagerIndicator 库是否有您喜欢的允许您配置字体的库。