自定义字体已损坏

时间:2015-01-19 09:56:33

标签: android android-view typeface android-typeface

我已经实现了TypefaceHelper缓存字体:

public class TypefaceHelper {

  private static final Hashtable<String, Typeface> FONT_CACHE = new Hashtable<>();

  private static Typeface get(String name) {
     synchronized (FONT_CACHE) {
        if (!FONT_CACHE.containsKey(name)) {
            FONT_CACHE.put(name, Typeface.createFromAsset(App.getContext().getAssets(), name));
        }

        return FONT_CACHE.get(name);
     }
  }

  public static Typeface getTypeFace(MyTypeFace typeface) {
     switch (typeface) {
        default:
        case ROBOTO_REGULAR:
            return get("fonts/Roboto-Regular.ttf");
        case ROBOTO_BOLD:
            return get("fonts/Roboto-Bold.ttf");
        case ROBOTO_LIGHT:
            return get("fonts/Roboto-Light.ttf");
     }
  }

  public enum MyTypeFace {
    ROBOTO_BOLD,
    ROBOTO_LIGHT,
    ROBOTO_REGULAR
  }

}

不幸的是,我现在面临着非常奇怪的问题。我的所有文本有时(随机)都没有正确呈现。它看起来像这样:

Corrupted texts

提前致谢。

0 个答案:

没有答案