Android 5.0 (API 21) fails to render custom fonts / typefaces

北城余情 提交于 2019-12-20 02:05:54

问题


Android 5.0 seems to have trouble rendering custom fonts. This issue does not occur pre Android 5.0 and it does not occur in Android 5.1 (API 22). Here is an example using a font called "coaster", available here: http://www.dafont.com/coaster.font

API 21:

API 22:

Any explanation for this?


回答1:


Google has acknowledged that this was an issue in Android 5.0, and has fixed it in Android 5.1: https://code.google.com/p/android-developer-preview/issues/detail?id=608&thanks=608&ts=1404735239

As for getting custom fonts to work on Android 5.0, there is a recommended work around in the issue page that I linked to above. It is post #16 on the issue. You need to convert your TTF font file to TTX and then convert it from TTX to TTF. You can use this tool to do so: https://github.com/behdad/fonttools/

I found these guides to be helpful for setting up fonttools:

Windows: http://glyphrstudio.com/ttx/

OSX:http://www.fontgeek.net/blog/?p=435

After installed, in terminal or the command prompt navigate to the directory where your TTF file is and run the command:

ttx font_file.ttf

Where "font_file" is the name of your, well, font file. This will output a font_file.ttx file in the directory you are currently in. Then, on this new font_file.ttx file, simply run the command:

ttx font_file.ttx

This will output a new TTF file of your font, and you can use this one in your Android project. These steps worked for me.



来源:https://stackoverflow.com/questions/29584569/android-5-0-api-21-fails-to-render-custom-fonts-typefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!