字符编码-如何在android中显示泰卢固语字体



我想在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("హైదరాబాద్");

请帮我一下。提前谢谢。

删除/font以解决问题

您可以使用名为font的子文件夹,但它必须位于assets文件夹中,而不是res

assets/res

Android

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

只需在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));

编辑:

现在看看这里的答案,它可能会帮助你们:斯塔克科弗流,他们和你们有同样的问题。

在值文件夹中的string.xml中写入一项

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

然后将您的字体文件保存在资产文件夹中

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

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

将其用于您的TextView

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

从字符串.xml文件夹设置文本

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

最新更新