views:

539

answers:

3

Hi,

I want to use a custom font for my android application which I am creating.
I can individually change the typeface of each object from Code, but I have hundreds of them.

So,

  • Is there a way to do this from the XML? [Setting a custom typeface]
  • Is there a way to do it from code in one place, to say that the whole application and all the components should use the custom typeface instead of the default one?

Thanks.
-Codevalley

+3  A: 

Is there a way to do this from the XML?

No, sorry. You can only specify the built-in typefaces through XML.

Is there a way to do it from code in one place, to say that the whole application and all the components should use the custom typeface instead of the default one?

Not that I am aware of.

CommonsWare
Love how you always say sorry when answering negatively to a request, like it was your fault. LOL ;-)
JRL
Oh! That is really disappointng. I have been searching the whole internet and was optimistic. Does that mean, I have to, from the code set the typeface for *each* UI component?
Codevalley
@Codevalley: Well, in many ways, the better answer is not to fuss with custom fonts. They tend to be large, making your downloads bigger and reducing the number of people who will download and keep using your app.
CommonsWare
@CommonsWare: I don't necessarily agree. Typeface is a integral part of UI Styling like you do with backgrounds images etc. And size is not necessarily big always. For instance, the font in my case is just 19.6KB :)
Codevalley
Wouldn't it be possible to create a custom theme, with the wanted typeface?
Sephy
@Sephy Unfortunately, only way to load custom Typefaces in Android is by specifying that in code. You can't do that from XML.
Codevalley
+1  A: 

This information is wrong. You can have custom fonts in your application.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");

number.setTypeface(tf); - textview

Hades
Please read the question completely. I specifically asked if this could be done from XML, or from single place in code. Not for each UI object separately.
Codevalley
A: 

@Codevalley I am sorry i am just repeating your question. What have you done finally to this problem? I am facing the same problem. Did u get any solution?

Hithen
@Hithen Unfortunately, only way to load custom Typefaces in Android is by specifying that in code. You can't do that from XML.
Codevalley