[英]FontAwesome icons doesn't get displayed on Android App
我已經在我的應用程序中將FontAwesome用於圖標。 特別是在某些TextViews中。 由於我希望在某些特定的文本視圖中使用該視圖,因此我創建了一個自定義的文本視圖。
public class FontAwesomeTextView extends TextView {
public FontAwesomeTextView(Context context) {
super(context);
}
public FontAwesomeTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public FontAwesomeTextView(Context context, AttributeSet attributeSet, int style) {
super(context, attributeSet, style);
}
@Override
public void setTypeface(Typeface tf, int style) {
String fontPath = "fonts/fontawesome.ttf";
Typeface typeFace = Typeface.createFromAsset(getContext().getAssets(), fontPath);
this.setTypeface(typeFace);
}
}
當我使用此按鈕並添加關閉圖標時,它會在帶有API 18的Genymotion模擬器上完美顯示,但是當我在使用API 21的手機上運行該應用程序時,它們將無法正確顯示或顯示叉號。
是什么導致此錯誤? 有任何解決辦法嗎?
問題出在API。 已知Android 5.0.x會出現此問題。 如下所述,請通過將TTf轉換為OTF進行修復。 (在某些情況下仍可能無法正常工作。)已知Android 5.1.x已修復此問題。
在5.1之前的Lollipop版本中,使用API Typeface.createFromAsset()
加載的某些自定義字體未使用正確的字體呈現。 此問題已在Android 5.1發行版中修復,但仍會影響運行Android Lollipop 5.0.x.
應用程序用戶。
請嘗試將“ .TTF”文件轉換為“ .OTF”文件。 就我而言,它幫助我解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.