【问题标题】:How to display telugu font in android如何在android中显示泰卢固字体
【发布时间】:2014-06-18 22:28:20
【问题描述】:

我想在 android 4.0 及以上设备中显示泰卢固语字体泰卢固语字体将自动支持,但我在 4.0 以下设备中遇到问题。我使用了以下代码,但泰卢固语无法正确呈现。

   Typeface tf= Typeface.createFromAsset(this.getAssets(), "fonts/gautami.ttf");
   TextView telugu=(TextView)findViewById(R.id.telugu);
   telugu.setTypeface(tf);
   telugu.setText("హైదరాబాద్");

请帮助我。提前致谢。

【问题讨论】:

    标签: android character-encoding typeface text-rendering


    【解决方案1】:

    删除/font以解决您的问题

    您可以使用名为 fonts 的子文件夹,但它必须放在 assets 文件夹中,而不是 res 文件夹中。

    assets/res
    

    安卓

    TextView telugu = (TextView) findViewById(R.id.telugu);
    Typeface Typefacetf = Typeface.createFromAsset(getAssets(), "gautami.ttf");
    telugu.setTypeface(Typefacetf);
    telugu.setText("హైదరాబాద్");
    

    【讨论】:

    • 如果 android 原生提供,为什么要使用外部库。
    • 但是在 TextView 上提供硬编码值并不是好的 android,所以只需在 string.xml 中定义它,你的工作就完成了。
    • OP的主要问题是写/font所以删除它来解决这个问题。
    • 字体 tf= Typeface.createFromAsset(this.getAssets(), "fonts/gautami.ttf");清楚地表明它在 assets/fonts/gautami.ttf 中。
    • 您好,如果我在 4.0 设备以下的 android 中使用上述代码,文本无法正确呈现。
    【解决方案2】:

    只需在 string.xml 中定义你的字体

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="text_your_name">హైదరాబాద్</string>
    </resources>
    

    因为编码是utf-8,所以它会正确呈现。

    现在你可以使用这个来设置文本:

    telugu.setText(getResources().getString(R.string.text_your_name));
    

    编辑:

    现在在这里查看答案,它可能会对您有所帮助 :: stackoverflow 他们和您有同样的问题。

    【讨论】:

    • 您好,如果我在 4.0 设备以下的 android 中使用上述代码,文本无法正确呈现。
    • 我已经在 2.2 模拟器中测试过了。它不能正常工作。我会在 2.3.3 模拟器中检查它并告诉你。
    • 不只是在真实设备中检查它,这样你就会得到确切的问题。
    • 您好,我在真机上测试过,问题依然存在。设备版本2.3.5。
    【解决方案3】:

    在 values 文件夹中的 string.xml 中写入一个项目

    <string name="your_text">హైదరాబాద్</string>
    

    然后将字体文件保存在 assets 文件夹中

    然后使用 assets 文件夹中的字体在 java 代码中创建自定义字体

    Typeface custom_type_face = Typeface.createFromAsset(getAssets(), "gautami.ttf");
    

    在你的 TextView 中使用它

    TextView telugu = (TextView) findViewById(R.id.telugu);
    telugu.setTypeface(custom_type_face);
    

    从 strings.xml 文件夹中设置文本

    telugu.setText(getResources().getString(R.string.your_text));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 2020-03-05
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多