0

I would like to use Roboto font as default font for every TextViews, EditTexts, Buttons, etc in my app.

I've put the ttf file in the fonts folder inside assets folder. Now I would like to edit the app style, in order to use that font. So, that's what I've done.

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:typeface">ROBOTO-REGULAR.TTF</item>
</style>

But the compiler returns this error.

String types not allowed (at 'android:typeface' with value 'ROBOTO-
 REGULAR.TTF').

Is it possible to define via XML a default font for the app? In this case, what is wrong? Thank you in advance.

Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71

1 Answers1

4

You can't do it the way you want. The android:typeface attribute is an enum and has a fixed number of values. It doesn't take a filename.

What you can do is implement a custom TextView (plus custom Button and EditText inheriting from their respective classes) that reads a custom attribute and loads the font file that the attribute points to.

Bear in mind that Roboto is meant to be used from Honeycomb onwards (or was it ICS?). It does look a bit out of place on older devices, where Droid Sans is the system-wide default.

Delyan
  • 8,881
  • 4
  • 37
  • 42
  • Ah ok thanks. So you're suggesting to keep the default font right? Btw it should be from ICS+. – Daniele Vitali Oct 06 '13 at 10:41
  • 1
    Well, it's up to your design, really. It's better to be consistent within the app and with the framework. On the other hand, if you're backporting the Holo-styled widgets, those look weird with anything other than Roboto. It's a judgement call but my rule of thumb is, 'has the user seen anything like this?' If the answer is no, I must have a very, very good reason to do it. – Delyan Oct 06 '13 at 10:49
  • Hi Delyan, I have created custom textview and button as you suggested but those custom views are not showing as bold if i set its textStyle from xml file. i know this question is closed but still if you can suggest some way to implement this – silwar Mar 25 '14 at 07:10
  • As a side note: Android studio users need to create an assests folder in src/main because of gradle build rather than the build/assets folder. http://stackoverflow.com/questions/18302603/where-to-place-assets-folder-in-android-studio/18302624#18302624 – cjayem13 Oct 12 '14 at 02:07