添加自定义字体的完整的Android应用程序 [英] Add custom font for complete android application
本文介绍了添加自定义字体的完整的Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序需要使用Helvetica字体的所有textviews和编辑文本字段。有没有办法做到这一点除了使用settypeface方法对每个TextView的?任何建议将是一个很大的帮助。
In my application I need to use helvetica font for all the textviews and edit-text fields. Is there any way to do this other than using settypeface method for every textview ? Any suggestion would be a great help.
在此先感谢!
推荐答案
我想,这也使我的自我。这是code我用。我创建自定义的的TextView
具有自定义字体作为默认字体。
I figured it out by my self. This is the code I used. I create custom TextView
which has custom font as default font.
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();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
setTypeface(tf ,1);
}
}
这篇关于添加自定义字体的完整的Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文