Android中是否支持所有字体?

时间:2014-01-10 14:26:12

标签: android fonts android-fonts

我已经安装并使用了以下字体

  • Antartida Rounded Black
  • Antartida圆形黑色斜体
  • Antartida Rounded Bold
  • Antartida Rounded Bold Italic
  • Antartida Rounded Light
  • Antartida Rounded Light Italic
  • Antartida Rounded Medium
  • Antartida Rounded Medium Italic

并使用代码添加字体

Typeface tp = TypeFaces.get(context, "font/AntartidaRounded-Black.ttf");
textView.setTypeface(tp);

设置字体

public class TypeFaces {
private static final String TAG = "Typefaces";

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

public static Typeface get(Context c, String assetPath) {
synchronized (cache) {
if (!cache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(c.getAssets(), assetPath);
cache.put(assetPath, t);
} catch (Exception e) {
Log.e(TAG, "Could not get typeface '" + assetPath + "' because " + e.getMessage());
return null;
}
}
return cache.get(assetPath);
}
}
}

使用

Typeface tf = TypeFaces.get(c, "font/AntartidaRounded-Bold.ttf");

这有什么不对吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

Typeface类没有get方法,所以我甚至不确定你从哪里得到它...

您要找的是Typeface#createFromAsset