在项目使用我们可能会遇到客户要求不使用系统自带的字体,这时我们就需要网上找字体资料,下载下来放入到工程下的assets资源目录下,同时规范格式,在下面建立fonts文件夹,将已下载好的字体文件放入其中,android系统支持的是ttf格式的字体文件。
在程序中如何调用:
public static Typeface getTypeface(Context context, String path) {
return Typeface.createFromAsset(context.getAssets(), path);
}
Typeface typeface = Utils.getTypeface(this, "fonts/wawati.ttf");
TextView text = new TextView(this);
text.setTypeface(typeface);
这样就可以使用自定义的字体效果了。