Я использую специальный шрифт для TextView и EditText в приложении для Android. Я сделал отдельный класс для шрифтов edittext и textview. Я использую шрифт Calibri для моего текста.Ошибка при настройке стиля пользовательского текста в моем приложении
Но после того, как работает мое приложение, она показывает следующее сообщение об ошибке во всех файлах, как -
com.pack.demo.MyFontedTextView не удалось создать экземпляр, где MyFontedTextView является файл класса и com.pack.demo.MyFontedEditText не удалось экземпляр.
Во всех моих макетах, я получаю исключение во время выполнения, как -.
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) показывает ошибки в Typeface шрифта = Typeface.createFromAsset (контекст .getAssets(), "calibri.otf"); в файле ниже класса.
Вот код для моего 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);
}
}
Точно так же, мой код для 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);
}
}
Добавить ваш шрифт в папку с данными? – Sishin
@ Sishin..yes я добавил, но все еще его не работает. – Ashutosh
Я думаю, что это ошибка типографии. как только проверьте имя файла .ttf на имя, указанное в классе. – Sonali8890