android ttc字体,android从ttc字体设置默认字体和字体系列
我有一個ttc font系列文件(在Mac上打開時可以看到),我想將其中一種樣式設置為默認font并進行一些更改textView中的字體與該字體家族的另一種樣式。
在此post和此post中,我用這些答案嘗試了很多事情。
我也已經讀過這個documentation。但這對我沒有幫助。
在嘗試的每個答案上,我都會遇到不同的錯誤,例如找不到font文件,無法為TextView充氣(當我啟動應用程序時,由于存在font文件我猜)。
我目前的情況是:
我的avenir.ttc文件位于font文件夾下的res文件夾下。
我已將這一行放在我的styles.xml中:
@font/avenir
當我在override文件中Application時,
TypeFaceUtil.overrideFont(applicationContext, "font/avenir.ttc")
方法:
fun overrideFont(context: Context, customFontFileNameInAssets: String) {
val customFontTypeface = Typeface.createFromAsset(context.assets, customFontFileNameInAssets)
val newMap = HashMap()
newMap["avenir"] = customFontTypeface
try {
val staticField = Typeface::class.java
.getDeclaredField("sSystemFontMap")
staticField.isAccessible = true
staticField.set(null, newMap)
} catch (e: NoSuchFieldException) {
e.printStackTrace()
} catch (e: IllegalAccessException) {
e.printStackTrace()
}
}
,我收到以下錯誤:
找不到字體資產font / avenir.ttc
總結
以上是生活随笔為你收集整理的android ttc字体,android从ttc字体设置默认字体和字体系列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php phalcon.dll 下载,e
- 下一篇: iOS 字体加粗