1、首先来说下两种创建方式

(1)这种要放在assets文件夹下

Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),"fonts/font.ttf");

(2)   而这种是指定路径的

Typeface typeface = Typeface.createFromFile("/mnt/sdcard/font.ttf");

2、使用方法

(1)textview字体设置

TextView tv = (TextView)findViewById(R.id.TextView01);

tv.setTypeface(typeface);

(2)Canvas上写字字体设置

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

paint.setTypeface(typeface);

anvas.drawText(str , rect.left , rect.top+height , paint);

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐