【发布时间】:2014-01-23 10:13:50
【问题描述】:
我的代码中存在一个巨大的问题,其中我从自定义 TextView 类加载我的 assets\fonts\ 文件夹中的字体。第一个问题是它在 4.0 设备上崩溃,但 Caused by: java.lang.RuntimeException: native typeface cannot be made 除外。我正在使用相同的过程here 方法:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context) {
super(context);
}
public void setTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupronbold.ttf"));
} else if (style == Typeface.ITALIC) {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupronitalic.ttf"));
} else {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupron.ttf"));
}
}
}
请注意,我正在使用扩展名.ttf,我发现这是导致RunTimeException 的原因。所以我用.otf 扩展名转换了各自的字体,现在它已经在4.0 设备中运行,但基于here 存在内存泄漏。有解决方法here,但我不知道如何使用/调用它。任何帮助都可以,谢谢。
【问题讨论】:
标签: android memory-leaks runtimeexception android-fonts inflate-exception