アプリケーション内のフォントスタイルを変更します。
今
アプリケーション
という名前のフォントを上書きするために別のクラスを作成
import java.lang.reflect.Field;
import android.content.Context;
import android.graphics.Typeface;
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();
}
}
}
FontOverride
をという名前の単純なクラスを作成します今
public final class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/GeezEdit.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/GeezEdit.ttf");
/*FontsOverride.setDefaultFont(this, "MONOSPACE", "MyFontAsset2.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "MyFontAsset3.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "MyFontAsset4.ttf");*/
}
}
android:name=".Application"
これは変更に動作するアプリケーションのタグ内のAndroidマニフェストファイルで最後の言及で、値フォルダ
<item name="android:typeface">monospace</item>
でアンドロイドのスタイルファイルでのスタイルにアプリケーション名をこの書体を追加ユーザーはAndroidプロジェクトまたはアプリケーションにフォントを提供しました。
この回答は機能していますが、アプリケーション外でフォントを変更する必要があります。 –