我想在android中显示hindi文本但无法解析

时间:2014-01-26 09:01:43

标签: android true-type-fonts android-assets

我在资源中添加了hindi .ttf文件,这是我的应用程序代码

public class NanTV extends TextView{

private Context c;
public NanTV(Context c) {
      super(c);
    this.c = c;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
    setTypeface(tfs);

  }
public NanTV(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.c = context;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
    setTypeface(tfs);
    // TODO Auto-generated constructor stub
}

public NanTV(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.c = context;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
    setTypeface(tfs);

}

} 当我试图在像这样的活动文件的textview中显示它

public class NanTV extends TextView{

private Context c;
public NanTV(Context c) {
    super(c);
    this.c = c;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
    setTypeface(tfs);

}
public NanTV(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.c = context;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
    setTypeface(tfs);
    // TODO Auto-generated constructor stub
}

  public NanTV(Context context, AttributeSet attrs) {
     super(context, attrs);
    this.c = context;
    Typeface tfs = Typeface.createFromAsset(c.getAssets(),
            "vigyapti.ttf");
      setTypeface(tfs);

  }

我在其中收到以下错误

01-26 14:18:27.090: E/AndroidRuntime(266): FATAL EXCEPTION: main
 01-26 14:18:27.090: E/AndroidRuntime(266): java.lang.RuntimeException: Unable to start      activity ComponentInfo{example.login/example.login.LoginActivity}:   

android.view.InflateException: Binary XML file line #8: Error inflating class    
 com.nannu.NanTV

这是我的布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
 >

  <com.nannu.NanTV
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge" 

    />

请帮助我,因为我需要一个快速的解决方案 感谢!!!

1 个答案:

答案 0 :(得分:0)

尝试使用OpenTypeFont文件字体