実際には、アプリケーション全体に共通のカスタム フォントを実装する方法はありません。ここでチェックアウトつまり 、いいえ、アプリケーション全体のフォントを設定することはできません。
それでも試してみたい場合は、以下のように参照してください。
一般的なフォント クラス:
public final class FontsOverride {
public static void setDefaultFont(Context context,
String staticTypefaceFieldName, String fontAssetName) {
final Typeface regular = Typeface.createFromAsset(context.getAssets(),
fontAssetName);
replaceFont(staticTypefaceFieldName, regular);
}
protected static void replaceFont(String staticTypefaceFieldName,
final Typeface newTypeface) {
try {
final Field StaticField = Typeface.class
.getDeclaredField(staticTypefaceFieldName);
StaticField.setAccessible(true);
StaticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
次に、いくつかのデフォルト フォントをオーバーロードする必要があります。次に例を示します。
FontsOverride.setDefaultFont(this, "DEFAULT", "MyFontAsset.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "MyFontAsset2.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "MyFontAsset3.ttf");
もちろん、同じフォント ファイルを使用している場合は、これを改善して一度だけ読み込むようにすることもできます。