在我的应用程序中,我需要对所有 TextView 和编辑文本字段使用 helvetica 字体。除了对每个 textview 使用 settypeface 方法之外,还有什么方法可以做到这一点?任何建议都会有很大帮助。
提前致谢!
最佳答案
我自己想通了。这是我使用的代码。我创建自定义 TextView
自定义字体作为默认字体。
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
private void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
setTypeface(tf ,1);
}
}
关于android - 为完整的 android 应用程序添加自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6926263/