【发布时间】:2018-06-05 02:09:34
【问题描述】:
我在 Android 应用中使用了很棒的字体。它没有显示真正的图标。相反,我得到了一些奇怪的文字。例如,我期待看到arrow-left,而我得到的是这个(如图所示)。
android:text="@string/fa_arrow_left"
userTV.setTypeface(TypeFaces.get(this.getApplicationContext(), "fa"));
这里是 TypeFaces 类。
public class TypeFaces {
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
public static Typeface get(Context c, String name) {
synchronized (cache) {
if (!cache.containsKey(name)) {
Typeface t = Typeface.createFromAsset(
c.getAssets(),
String.format("fonts/%s.ttf", name)
);
cache.put(name, t);
}
return cache.get(name);
}
}
}
在strings.xml中<string name="fa_arrow_left">&#xf060;</string>
fa.ttf 放在main > assets > fonts
从https://github.com/FortAwesome/Font-Awesome/blob/master/fonts/fontawesome-webfont.ttf下载字体
不管怎样☺
【问题讨论】:
标签: android encoding font-awesome android-typeface