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);

有人在 android 4.4 kit-kat 中有这些问题吗?

4

4 回答 4

5

我有一个类似的问题,并找到了这个线程。看看是否有帮助。

自定义 ttf 字体在 Android 4.4 KitKat 上的 TextView 中无法正确显示

编辑:

我在使用 calibri.ttf 时遇到了同样的问题。我切换到 lato.ttf(可在 google.com/fonts 上获得),它们工作正常/看起来非常相似。

于 2013-12-13T17:22:05.143 回答
1

我有同样的问题,我在我的应用程序中使用 AppleLiGothic.ttf 字体,文件大小为 5mb。无论如何,后来我将字体更改为 Roboto-Light.ttf 。我从 android19 sdk 数据文件夹中获取了这个字体。我认为目前某些字体可能不兼容,最好尝试一些字体,直到找到哪种字体有效。

于 2013-12-18T10:14:46.463 回答
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 上)

于 2015-04-20T15:19:30.297 回答
0

我一直在做的是将字体放在资产文件夹中并像这样加载它:

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

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

于 2013-12-03T20:46:43.323 回答