有沒有什麼辦法在android棒棒糖中使用geomanist(自定義)字體。自定義字體不工作在棒棒糖
但它適用於所有其他版本。
這裏是我的代碼
在MyApplication的類
FontsOverride.setDefaultFont(this, "DEFAULT", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "geomanist-lightnew.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "geomanist-lightnew.ttf");
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();
}
}
}
感謝
讀https://stackoverflow.com/questions/33923803/how-to-set-custom-字體爲整個應用程序在Android –