views:

2711

answers:

2

hello..

i want to use external fonts in my app. i have tried adding new fonts using asset managers but it did not work.

Typeface face;

face = Typeface.createFromAsset(getAssets(), "font.otf");

textview.setTypeface(face);

but it did not show the text...

plz help..

+2  A: 

AFAIK, Android does not support OpenType. Use a TrueType font instead.

CommonsWare
so you are saying that i am in right direction..i just need to use ttf file instead of otf???
mudit
Yes. Given your code, you need your font to be in the root of your assets/ directory, but otherwise it should be fine with a compatible font.
CommonsWare
hi..I hv tried usinf ttf files.but still font is not loading.It is setting DEFAULT font in case of my font. there is also an error msg is displaying in my console.Error msg--Starting activity com.test.abc on device [2009-09-21 14:56:32 - test] ActivityManager: DDM dispatch reg wait timeout[2009-09-21 14:56:32 - test] ActivityManager: Can't dispatch DDM chunk 52454151: no handler defined[2009-09-21 14:56:32 - test] ActivityManager: Can't dispatch DDM chunk 48454c4f: no handler defined[2009-09-21 14:56:38 - test] ActivityManager: Starting: Intent { comp={com.test/com.test.abc} }
mudit
The error message indicates some communications difficulty between your emulator and either adb or Eclipse -- it has nothing to do with fonts. Download http://commonsware.com/Android/Android-src-2_1.zip and you will find an Android project that shows loading a TrueType font. Also note that Android 1.6 now appears to let you load fonts from outside of the APK (e.g., one you download separately).
CommonsWare
A: 

I was having the same problem. My font was not working in android either but I needed it to work. Using a font editor, I copied the characters from my font into the font that comes with the FontSampler example from Android-src-2_1. It worked perfectly.

While I will admit that my method was questionable from an intellectual property point of view, I didn't actually wind up using the original font, as all of the characters were replaced and all references to the old font where replaced as well. I had tried 'looking' at the way the two fonts were defined but making all the font variables match didn't work either. So in the ned, I used a skeleton of the original font as a template for the new font.

dave evartt