I am using custom fonts in my application So I have used following code
public class BrandonBlackTextView extends TextView {
public BrandonBlackTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public BrandonBlackTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BrandonBlackTextView(Context context) {
super(context);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/brandon_blk.ttf");
setTypeface(tf ,1);
}
wherever I wants to use I use this textview
. It works.
But problem is sometimes I don't know why but text inside textview
becomes bold. I don't know why this happening. And this is very inconsistent, it doesn't happen every time.
Try adding this to your init:
Also you should cache the typeface somewhere instead of loading it again for every
TextView
.