views:

1260

answers:

2

I'm trying to define a GUI layout using XML files in Android. As far as I can find out, there is no way to specify that your widgets should use a custom font (e.g. one you've placed in assets/font/) in XML files and you can only use the system installed fonts.

I know that, in the Java code, I could change the font of each widget manually using unique IDs. Alternatively, I could iterate over all the widgets in Java to make this change, but this would probably be very slow.

What other options do I have? Is there any better ways to making widgets that have a custom look? I don't particularly want to have to manually change the font for every new widget I add.

+1  A: 

You don't have any other options, other than perhaps writing your own code generator or something. Sorry!

CommonsWare
Thanks. Wow, is it just me, or is this a huge problem? For polished games, you usually want a custom look to your widgets e.g. buttons. Ideally, I would just write a style xml file and get all my buttons using the same fonts and colors. Now, any time a button could be generated or appear in a layout, I'm going to have to add code to change its font... I suppose I could write my own button class that updates its own font and refer to that class in the XML files. I'm befuddled the API is making me do this though.
DrDefrost
Fonts are kinda big, particularly if you are going to offer translations of your strings into various languages. Moreover, "polished games" aren't going to be using the widget system anyway -- they'll draw straight to the Canvas (in which case, your fonts and system fonts are roughly equivalent) or use OpenGL (and I have no idea how font handling behaves here). If non-game apps infrequently have a compelling need for large custom fonts, and if most game apps won't use widgets, the extra font hassle with widgets isn't a big deal, and Android team engineering time is limited.
CommonsWare
How stupid! I hope its gonna be implemented in the next SDK version.
OneWorld
A: 

The only way to use custom fonts is through the source code.

Just remember that Android runs on devices with very limited resources and fonts might require a good amount of RAM. The built-in Droid fonts are specially made and, if you note, have many characters and decorations missing.

tareqHs