【问题标题】:Problems with fonts in android 4.4android 4.4中的字体问题
【发布时间】:2013-11-01 13:45:04
【问题描述】:

今天我已将我的 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 中遇到过这些问题吗?

【问题讨论】:

  • 仍在下载...但我对 google play 服务库更新更感兴趣。
  • 我遇到了同样的问题。我的自定义字体未在 KitKat 上呈现。由于它是我尝试使用的字形字体,如果找不到解决方案,我将不得不恢复为 imagesviews
  • 我遇到了同样的问题,我使用了自定义字体,现在它不适用于 kitkat。
  • HTML 是否偶然使用粗体和/或斜体?如果是这样,很可能您遇到了code.google.com/p/android/issues/detail?id=61771,这是一个已知问题。
  • 第一次我不使用 HTML 文本,但有这个问题。但第二次你是对的。

标签: android android-4.4-kitkat


【解决方案1】:

我遇到了类似的问题,找到了这个帖子。看看有没有帮助。

Custom ttf fonts are not showing properly in TextView on Android 4.4 KitKat

编辑:

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

【讨论】:

  • 你帮帮我吧!非常感谢。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    字体在 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 上)

    【讨论】:

      【解决方案4】:

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

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

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

      【讨论】:

      • 是的,我的代码是一样的,我用粗体没有问题,但是用普通字体就没有那么简单了
      • 尝试使用开放式字体,它适用于“calibri.otf”。这确实是一个烦人的错误..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      • 2018-07-23
      相关资源
      最近更新 更多