自定义 ttf 字体在 Android 4.4 KitKat 上的 TextView 中无法正确显示 [英] Custom ttf fonts are not showing properly in TextView on Android 4.4 KitKat

查看:37
本文介绍了自定义 ttf 字体在 Android 4.4 KitKat 上的 TextView 中无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有粗体部分的文本.直到 KitKat 这种策略(如本文所述) 效果很好

I have some text which has some bolded parts. Until KitKat this strategy (as mentioned in this post) worked perfectly well

我的字符串资源文件:

<string name="multi_style_text">NON-BOLD TEXT 
<b>BOLD</b></string>

我在片段中的应用代码:

My application code in fragment:

txtView.setTypeface(FontUtils.getOstrichRegular(this.getActivity()));
...
public static Typeface getOstrichRegular(Context context) {
   return Typeface.createFromAsset(context.getAssets(),
                                "fonts/ostrich_regular.ttf");
}

目前(在 KitKat 中),粗体部分不以自定义字体显示,非粗体部分以自定义字体显示.在以前的 Android 版本中,所有文本都以自定义字体显示.

Currently (in KitKat), the bolded part is not shown in the custom font, the non-bolded part is shown in the custom font. In previous versions of Android, all of the text was shown in the custom font.

什么给了?

推荐答案

所以,在被这个 bug 搞砸之后,我四处寻找,找到了解决问题的方法.在我当前的项目中,我们使用 calibri.ttf 字体.直到 4.4 都可以正常工作.一旦我对我的 nexus 4 进行了更新,所有带有 Calibri 字体的 TextView 都显示ff"而不是整个文本.

So, after being frustrated by this bug, I searched around and found a solution to the problem. In my current project we use calibri.ttf font. that was working fine up to 4.4. Once i got the update to my nexus 4, All the TextViews with Calibri font were showing "ff" instead of the entire text.

修复 - 获取字体的 .otf(开放式字体)版本,并将其放入项目中,就像魅力一样.太糟糕了,谷歌没有就此通知开发人员,而且关于此事的文档很少.

THE FIX - get an .otf (open type font) version of your font, and put in the project, works like a charm. Too bad google didn't inform the developers on this and there's very little documentation on the matter.

这篇关于自定义 ttf 字体在 Android 4.4 KitKat 上的 TextView 中无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆