废话不多说,先上图
1、在assets下新建一个fonts文件,把字体样式 .TTF文件 放入
2、代码部分
@BindView(R.id.tv_tv)
TextView tvTv;
@BindView(R.id.tv_tv1)
TextView tvTv1;
@BindView(R.id.tv_tv2)
TextView tvTv2;
@BindView(R.id.tv_tv3)
TextView tvTv3;
AssetManager assets = getAssets();
Typeface tf = Typeface.createFromAsset(assets, "fonts/milaiti.ttf");
tvTv.setTypeface(tf);
Typeface tf1 = Typeface.createFromAsset(assets, "fonts/hua_kang_zhong_yi.ttf");
tvTv1.setTypeface(tf1);
Typeface tf2 = Typeface.createFromAsset(assets, "fonts/terminator_real_nfi.ttf");
tvTv2.setTypeface(tf2);
Typeface tf3 = Typeface.createFromAsset(assets, "fonts/hua_kang_girl.ttf");
tvTv3.setTypeface(tf3);
以上代码就可以实现字体特殊样式了,布局部分过于简单就不粘贴出来了。
如果先让自己的TextView 字体都显示想要的特殊样式,可以 继承 TextView 重新 自定义View。
自定义TextVIew代码
package com.bang.myapplication;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
/**
* DateTime: 2019/4/17 19:07
* author: Bang
* description: 特殊字体样式
*/
public class TffTextView extends android.support.v7.widget.AppCompatTextView {
public TffTextView(Context context) {
super(context);
}
public TffTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setTypeface(@Nullable Typeface tf) {
AssetManager assets = getContext().getAssets();
tf = Typeface.createFromAsset(assets, "fonts/hua_kang_girl.ttf");
super.setTypeface(tf);
}
}
布局引用
<com.bang.myapplication.TffTextView
android:id="@+id/tff_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/zyfc"
android:textSize="30sp"/>
以上字体样式下载地址
https://download.csdn.net/download/qq_37686995/11123431