[英]Setting TextView to bold font with xml-attribute and custom font (not working)
[英]Setting custom font to Textview
我在应用程序中使用自定义字体,所以我使用了以下代码
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);
}
我想在哪里使用我都使用这个textview
。 有用。 但是问题是有时我不知道为什么,但是textview
文本变为粗体 。 我不知道为什么会这样。 这是非常不一致的,并非每次都会发生。
尝试将其添加到您的init中:
int flags = getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG;
setPaintFlags(flags);
另外,您应该将字体缓存在某个地方,而不是为每个TextView
再次加载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.