【问题标题】:Android Tamil font between english word英文单词之间的Android泰米尔语字体
【发布时间】:2012-05-17 12:11:21
【问题描述】:

我有一个 TextView,其中有一个巨大的文本我有一个泰米尔语单词,我知道如何在单独的 textview 中嵌入泰米尔语字体。但我需要英语单词之间的泰米尔语单词,请提前帮助谢谢

我在 textview 中的部分文字:

欢迎 (நல்வரவு) 等季节性消息在 Kolam 中使用。 有时会在寺庙自愿绘制kolam 奉献者的

【问题讨论】:

  • 嘿,您只想在 textview 中显示文本不?没有对其进行其他操作???
  • 是的,我只想显示文本,当我尝试在不同的文本视图中拆分文本时,我没有得到滚动视图
  • 我无法从 html 字符串中获取泰米尔语字体
  • 嗨。我正在尝试遵循您的方法,但仍然如您所见,“வு”一词未正确显示。不仅如此,还有其他的词也乱七八糟。您有什么想法或我如何正确显示它。

标签: android textview android-fonts tamil


【解决方案1】:

尝试通过 setTypeface 将 Akshar.ttf 字体设置为您的 TextView,它支持英语和泰米尔语。


结果如下:

或者,寻找支持这两种语言的类似字体。


您的第二个解决方案是使用 SpannableStringBuilder 为这个小的泰米尔语文本部分使用图像。


TextView自定义字体设置代码:

假设您在 assets 文件夹下的 fonts 文件夹中有 Akshar.ttf 字体:

 Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Akshar.ttf");               
    TextView tv = (TextView) findViewById(R.id.CustomFontText);
    tv.setTypeface(tf);
    tv.setText("Seasonal messages like welcome (நல்வரவு) is used in Kolam. Volunteering to draw kolam at temple is sometimes done when a devotee's");

【讨论】:

  • @ThiruVT 看看我的另一个答案,它更笼统:)
  • 嗨。我正在尝试遵循您的方法,但仍然如您所见,“வு”一词未正确显示。不仅如此,还有其他的词也乱七八糟。您有什么想法或我如何正确显示它。
  • @AndroSelva 复杂字形显示为损坏的字符。因此,我为我的 Bangla IME 使用文本到图像替换来显示那些复杂的字形,并使用叠加技术来减少所需的图像。
【解决方案2】:

如果您想在一个 TextView 中支持多种字体,但在单个 ttf 中不支持它们,还有另一种解决方案:

使用以下代码:(我使用的是孟加拉语和泰米尔语字体)

  TextView txt = (TextView) findViewById(R.id.custom_fonts);  
        txt.setTextSize(30);
        Typeface font = Typeface.createFromAsset(getAssets(), "Akshar.ttf");
        Typeface font2 = Typeface.createFromAsset(getAssets(), "bangla.ttf");   
        SpannableStringBuilder SS = new SpannableStringBuilder("আমারநல்வரவு");
        SS.setSpan (new CustomTypefaceSpan("", font2), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        SS.setSpan (new CustomTypefaceSpan("", font), 4, 11,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        txt.setText(SS);

结果是:


CustomTypefaceSpan 类:

package my.app;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;

public class CustomTypefaceSpan extends TypefaceSpan {

private final Typeface newType;

public CustomTypefaceSpan(String family, Typeface type) {
    super(family);
    newType = type;
}

@Override
public void updateDrawState(TextPaint ds) {
    applyCustomTypeFace(ds, newType);
}

@Override
public void updateMeasureState(TextPaint paint) {
    applyCustomTypeFace(paint, newType);
}

private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
}

Reference

【讨论】:

    【解决方案3】:

    我在 Android 4.0 中遇到过这个问题。 我发现这是由于 csc(国家代码)。 如果是印度,那么泰米尔语可以正常工作,否则无法正常工作。 我可以确认一下。

    【讨论】:

      【解决方案4】:

      在 ICS (4.0) 之前,Android 系统中没有可用的泰米尔语字体。即便如此,它也有错误,Google 用 Jelly Bean (4.2) 修复了这一切。

      现在,如果您想在应用程序中显示泰米尔语,您需要使用 TAB、TAM、BAMINI 或 TSCII 编码。

      我写了一个simple library that does the conversion for you dynamically。您只需编写如下简单代码。

      // Initialise the Typeface (assumes TSCII, Bamini, Anjal, TAB or TAM font located inside assets/fonts folder)
      Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/mylai.ttf");
      // Initialises the TextView
      TextView tv = (TextView)findViewById(R.id.textView1);
      //Setting the Typeface
      tv.setTypeface(tf);
      //Magic happens here ;) encoding conversion
      String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII, "வணக்கம் அன்ரொயிட்");
      //Setting the new string to TextView
      tv.setText(TSCIIString);
      

      我已经写了更多关于这个topic in this answer. Please check it out too.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-31
        • 2013-12-23
        • 1970-01-01
        • 2012-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多