I am using a custom font for TextView and EditText in my android app. I have made a seperate class for fonted edittext and textview. I am using the Calibri font for my text.
But after running my app, it is showing following error in all files as -
com.pack.demo.MyFontedTextView failed to instantiate where MyFontedTextView is the class file and com.pack.demo.MyFontedEditText failed to instantiate.
In all my layouts, I am getting the runtime exception as -
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:175)
at android.graphics.Typeface.createFromAsset(Typeface.java:149)
at com.pack.demo.MyFontedTextView.<init>(MyFontedTextView.java:22)
com.pack.demo.MyFontedTextView.(MyFontedTextView.java:22) shows error in Typeface font = Typeface.createFromAsset(context.getAssets(), "calibri.otf"); in below class file.
Here is the code for my fonted edittext -
public class MyFontedEditText extends EditText {
public MyFontedEditText(Context context) {
super(context);
// TODO Auto-generated constructor stub
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
public MyFontedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
public MyFontedEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
}
Similarly, my code for fonted textview -
public class MyFontedTextView extends TextView {
public MyFontedTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
public MyFontedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
Log.d("1", "abc");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
public MyFontedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
}