Custom ttf fonts are not showing properly in TextView on Android 4.4 KitKat

后端 未结 5 1123
忘掉有多难
忘掉有多难 2020-12-19 04:06

I have some text which has some bolded parts. Until KitKat this strategy (as mentioned in this post) worked perfectly well

My strings resources file:



        
5条回答
  •  眼角桃花
    2020-12-19 04:09

    I resolved the problem by converting my file.ttf to file.otf

    remplace :

    Typeface typeface = Typeface.createFromAsset(activity.getAssets(), "fonts/ostrich_regular.ttf");
    yourTextView.setTypeface(typeface);
    

    by :

    Typeface typeface = Typeface.createFromAsset(activity.getAssets(), "fonts/ostrich_regular.otf");
    yourTextView.setTypeface(typeface);
    

    FYI : the .otf format work for all android version (not only on kitkat)

提交回复
热议问题