8

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:

<string name="multi_style_text">NON-BOLD TEXT \n<b>BOLD</b></string>

My application code in fragment:

txtView.setTypeface(FontUtils.getOstrichRegular(this.getActivity()));
...
public static Typeface getOstrichRegular(Context context) {
   return Typeface.createFromAsset(context.getAssets(),
                                "fonts/ostrich_regular.ttf");
}

Currently (in KitKat), the bolded part is not shown in the custom font, the non-bolded part is shown in the custom font. In previous versions of Android, all of the text was shown in the custom font.

What gives?

Community
  • 1
  • 1
KG -
  • 7,130
  • 12
  • 56
  • 72

5 Answers5

22

So, after being frustrated by this bug, I searched around and found a solution to the problem. In my current project we use calibri.ttf font. that was working fine up to 4.4. Once i got the update to my nexus 4, All the TextViews with Calibri font were showing "ff" instead of the entire text.

THE FIX - get an .otf (open type font) version of your font, and put in the project, works like a charm. Too bad google didn't inform the developers on this and there's very little documentation on the matter.

Israel Tabadi
  • 574
  • 4
  • 11
2

Apparently this is a bug in KitKat and has been fixed in an internal tree.

KG -
  • 7,130
  • 12
  • 56
  • 72
0

Put your custom font in android assets under folder name "font" or whatever you want

Try this

myTypeface = Typeface.createFromAsset(this.getAssets(),
            "fonts/<<your font>>.ttf");

in onCreate() then

[use youcontroll].setTypeface(myTypeface);

Best of Luck...

AmanVirdi
  • 1,667
  • 2
  • 22
  • 32
Arpan24x7
  • 648
  • 5
  • 24
0

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)

Netero
  • 3,761
  • 2
  • 29
  • 29
0

After many hours searching for roboto.otf (2014 year) I understood that it was a mistake. Simply download a normal ttf font from https://www.fontsquirrel.com/fonts/roboto-2014 and copy to assets folder, then use setTypeface. Also you may convert it to otf with any web-site.

CoolMind
  • 26,736
  • 15
  • 188
  • 224