我试图执行this代码到我的应用程序,并使用我的字体在assets/fonts
。我没有在logcat中得到任何异常,但每次启动it.It崩溃。什么是我做错了应用程序每次启动时崩溃没有任何错误
这里是mycode的
public class appp extends Application {
private Typeface normalFont;
private Typeface boldFont;
// -- Fonts -- //
public void setTypeface(TextView textView) {
if(textView != null) {
if(textView.getTypeface() != null && textView.getTypeface().isBold()) {
textView.setTypeface(getBoldFont());
} else {
textView.setTypeface(getNormalFont());
}
}
}
private Typeface getNormalFont() {
if(normalFont == null) {
normalFont = Typeface.createFromAsset(getAssets(),"fonts/SERSAL.ttf");
}
return this.normalFont;
}
private Typeface getBoldFont() {
if(boldFont == null) {
boldFont = Typeface.createFromAsset(getAssets(),"fonts/Cheboyga.ttf");
}
return this.boldFont;
}
}
,这是主类
appp application = (appp) getApplication();
TextView myTextView = (TextView) findViewById(R.id.my_textview);
application.setTypeface(myTextView);
您正在使用自定义应用程序,所以已经在您的清单中展示了这个** android:name =“your packagename.appp”**。 –
Withouy任何额外的类,你可以简单地使用这样的自定义字体 TextView myTextView =(TextView)findViewById(R.id.my_textview); Typeface tf = Typeface.createFromAsset(getAssets(),“fonts/SERSAL.ttf”); \t \t myTextView .setTypeface(tf); –
你能看到我的答案吗? –