我在资源中添加了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"
/>
请帮助我,因为我需要一个快速的解决方案 感谢!!!
答案 0 :(得分:0)
尝试使用OpenTypeFont
文件字体