くだらない話はしないで、まず写真を見に行きましょう
1. Assets の下に新しいフォント ファイルを作成し、 そこにfont style.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