Typeface xyz=Typeface.createFromAsset(view.getContext().getAssets(),
"fonts/xyz.ttf");
(TextView)abc.setTypeface(xyz);
This is how you create and set a custom typeface.
I need to set the typeface/font of a pagertitlestrip but there is no .setTypeFace function for pagertitlestrip. Does anyone know how I can do that anyway?
The PagerTitleStrip is actually extends ViewGroup, so you can just subclass it and iterate through each of its children to find the views that need their font to be changed:
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);
}
}
}
}
The only downside is that it prevents Eclipse from being able to display your layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With