5

I am using the following line of code to change the font type in android application :L

Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/Abumohammed.ttf"); 
textView.setTypeface(font);

I am sure that Abumohammed.ttf is in assets/fonts folder .. but the font don't change and don't has any effect on the textview !!

Adham
  • 63,550
  • 98
  • 229
  • 344

2 Answers2

4

Android does not support every font file. When it fails, it tends to fail silently, showing the default font instead. I have no idea what Android does not like about some of them.

I would find some font that definitely works, such as this one, and try it to make sure that the rest of your code is OK. If indeed you determine that the font file does not work, AFAIK you have no choice but to find some other font.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • as you see in this link http://www.4shared.com/folder/O2GzNe_h/android_Arabic_fonts.html >> when I extract the files and use their fonts I got this problem , despite it is supposed to to work fine in android – Adham Aug 02 '12 at 22:23
  • @Adham: All I can tell you to do is contained in my answer. Or, try my entire sample project: https://github.com/commonsguy/cw-omnibus/tree/master/Fonts/FontSampler – CommonsWare Aug 02 '12 at 22:26
2

I was annoyed enough by this that I thought I'd share some results of my digging. I tried a few font files that ended up using the fallback font. To 'fix' some of these files, I simply had to open the file in FontForge, then File->Generate Font and re-save as TTF. This allowed some that were not showing to draw properly.

Others required moving the glyphs from the Microsoft area (U+F030) to U+0030 range.

I haven't educated myself on what 'Generate Font' actually does. But, now that I know HOW to fix it, I can at least start to figure out why it isn't working. I suspect this can only be fixed in the AOSP tree however.

Jason
  • 21
  • 1