1
我剛剛嚮應用商店推出了一個應用,並且正在從人們那裏獲取有關使我的自定義TextView膨脹的錯誤,該錯誤用於實現自定義字體。這些錯誤似乎來自運行4.0.3或4.0.4的人,並且它在我的S3運行4.3以及Nexus 7上正常工作。是否有一些我錯過了使它兼容?我知道this SO question它有相同的問題,但並不完全解決它。我添加了一個try/catch使它默認回到內置字體,但它似乎應該有一個解決方案,所以我可以使用我的自定義字體。原生字體不能用於4.0.3-4.0.4
的logcat:
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 22 more
Caused by: java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:430)
at android.graphics.Typeface.createFromAsset(Typeface.java:404)
at com.gtf.oneparish.AvTextView.<init>(AvTextView.java:18)
... 25 more
AvTextView:
public class AvTextView extends TextView {
public static Typeface FONT_NAME;
public AvTextView(Context context) {
super(context);
try {
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/avenirlight.ttf");
this.setTypeface(FONT_NAME);
} catch (Exception e) {
Log.e("Font Creation error", "Could not get typeface because " + e.getMessage());
}
}
public AvTextView(Context context, AttributeSet attrs) {
super(context, attrs);
try {
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/avenirlight.ttf");
this.setTypeface(FONT_NAME);
} catch (Exception e) {
Log.e("Font Creation error", "Could not get typeface because " + e.getMessage());
}
}
public AvTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
try {
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/avenirlight.ttf");
this.setTypeface(FONT_NAME);
} catch (Exception e) {
Log.e("Font Creation error", "Could not get typeface because " + e.getMessage());
}
}
}