安卓4.4中的字体问题

12

第一张截图 第二张截图

今天我升级了Android SDK到19 API,并在测试我的应用程序时,在19 API中遇到了一些错误:文本视图中掉落了一些字体,或者它的大小存在问题。

第一个屏幕,一个视图的代码:

tvBalance = new TextView(getContext());
    rlParams = new LayoutParams(frame.width, (int) (frame.heigth * zoneExtetn));
    rlParams.setMargins(frame.left, (int) (frame.top - frame.heigth * (zoneUp-0.1f)), 0, 0);
    tvBalance.setLayoutParams(rlParams);
    tvBalance.setGravity(Gravity.CENTER);
    tvBalance.setPadding(0, 0, 0, 0);
    tvBalance.setTextColor(0xffffd008);
    tvBalance.setTextSize(PokerTextSize.scaleFont(getContext(), 28));
    tvBalance.setText("$ 0 000 000 000");
    tvBalance.setTypeface(TypefaceBase.getCalibri((Activity) getContext()));
    rlMoney.addView(tvBalance);

和第二屏幕代码:

TextView tvText = new TextView(llContent.getContext());
            llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            llParams.setMargins(0, 0, 0, marg*2);
            tvText.setLayoutParams(llParams);
            tvText.setTextSize(fonts[0]);
            tvText.setTextColor(articleColor);
            tvText.setText(Html.fromHtml(articleItem.getString()));
            tvText.setTypeface(TypefaceBase.getCalibri((Activity) this.getContext()));

            llContent.addView(tvText);

有人在安卓4.4 Kit-Kat系统中遇到这些问题吗?


仍在下载中...但我更关心的是Google Play服务库的更新。 - danny117
我遇到了完全相同的问题。我的自定义字体在KitKat上无法渲染。由于我尝试使用的是字形字体,如果找不到解决方案,我将不得不恢复到ImageViews。 - joseph
我遇到了同样的问题,我使用了自定义字体,现在它在KitKat上无法工作。 - Sunil Parmar
2
HTML 中是否使用了粗体和/或斜体?如果是,那么你很可能遇到了已知问题 http://code.google.com/p/android/issues/detail?id=61771。 - Raph Levien
第一次我没有使用HTML文本,但是遇到了这个问题。但是在第二次中你是正确的。 - Anton
看起来这个问题在4.4.1中已经被修复了。 - user3153206
4个回答

5

你帮了我!非常感谢。 - Milad Ghiravani

1

我的Android 4.4.2 (Kitkat)上也无法使用字体,我通过将我的file.ttf文件转换成file.otf解决了这个问题。

替换:

Typeface typeface = Typeface.createFromAsset(activity.getAssets(), "yourFont.ttf");
yourTextView.setTypeface(typeface);

由:

Typeface typeface = Typeface.createFromAsset(activity.getAssets(), "yourFont.otf");
yourTextView.setTypeface(typeface);

提示:.otf格式适用于所有Android版本(不仅限于KitKat)


1
我遇到了同样的问题,我的应用程序使用的是AppleLiGothic.ttf字体,文件大小约为5MB。后来我将字体更改为Roboto-Light.ttf。我从android19 sdk数据文件夹中获取了这个字体。我认为有些字体可能不兼容,最好尝试几个直到找到可用的为止。

0
我一直在做的是将字体放在资产文件夹中,并以此方式加载它:
Typeface typeface = Typeface.createFromAsset(activity.getAssets(), "yourFont.ttf");
yourTextView.setTypeface(typeface);

当我使用这种方法时,我在Kit Kat中没有遇到任何问题。


是的,我的代码是一样的,粗体字没有问题,但普通字体就不那么简单了。 - Anton
尝试使用开放式字体,我用“calibri.otf”成功了。这确实是一个令人烦恼的错误。 - Israel Tabadi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接