1、使用assets目录下字体(ttf文件)
在 assets\fonts\ 文件夹下添加要使用的字体(fonts 可以是任意名字)
var face: Typeface = Typeface.createFromAsset(context.assets,"fonts/raygun.ttf");
//1、对 Paint 设置,进行绘制
var mNormalTextPaint: Paint = Paint()
mNormalTextPaint!!.typeface = face
//2、对 TextView 进行设置
tv.typeface = face
2、使用 res\font 文件夹下的字体
在 res 文件夹下创建 font 文件夹,将字体文件放入到该文件夹下
在 相应的xml 文件中加入 android:fontFamily="@font/raygun"
<TextView
。。。
android:fontFamily="@font/raygun"/>