276

In the answer to this question the user lists values for android:fontFamily and 12 variants (see below). Where do these values come from? The documentation for android:fontFamily does not list this information in any place (I checked here, and here). The strings are listed in the Android styles.xml file in various places, but how do these map back to the Roboto font?

From android 4.1 / 4.2, the following Roboto font families are available:

android:fontFamily="sans-serif"           // roboto regular  
android:fontFamily="sans-serif-light"     // roboto light  
android:fontFamily="sans-serif-condensed" // roboto condensed  
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)  
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

in combination with this

android:textStyle="normal|bold|italic" 

12 variants are possible:

  • Regular
  • Italic
  • Bold
  • Bold-italic
  • Light
  • Light-italic
  • Thin
  • Thin-italic
  • Condensed regular
  • Condensed italic
  • Condensed bold
  • Condensed bold-italic

In the styles.xml file in the application I'm working on somebody listed this as the font family, and I'm pretty sure it's wrong:

<item name="android:fontFamily">Roboto-Regular.ttf</item>

I'd like to get the theme for our app set up correctly (which includes using fontFamily correctly) and remove all the redundancy that is in some of the styles that were created before I had a look at the file.

Community
  • 1
  • 1
Christopher Perry
  • 36,832
  • 42
  • 136
  • 182

3 Answers3

356

Where do these values come from? The documentation for android:fontFamily does not list this information in any place

These are indeed not listed in the documentation. But they are mentioned here under the section 'Font families'. The document lists every new public API for Android Jelly Bean 4.1.

In the styles.xml file in the application I'm working on somebody listed this as the font family, and I'm pretty sure it's wrong:

Yes, that's wrong. You don't reference the font file, you have to use the font name mentioned in the linked document above. In this case it should have been this:

<item name="android:fontFamily">sans-serif</item>

Like the linked answer already stated, 12 variants are possible:

Added in Android Jelly Bean (4.1) - API 16 :

Regular (default):

<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">normal</item> 

Italic:

<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">italic</item>

Bold:

<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item>

Bold-italic:

<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold|italic</item>

Light:

<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>

Light-italic:

<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">italic</item>

Thin :

<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">normal</item>

Thin-italic :

<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">italic</item>

Condensed regular:

<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">normal</item>

Condensed italic:

<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">italic</item>

Condensed bold:

<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold</item>

Condensed bold-italic:

<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold|italic</item>

Added in Android Lollipop (v5.0) - API 21 :

Medium:

<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">normal</item>

Medium-italic:

<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">italic</item>

Black:

<item name="android:fontFamily">sans-serif-black</item>
<item name="android:textStyle">italic</item>

For quick reference, this is how they all look like:

arekolek
  • 7,180
  • 1
  • 50
  • 71
Ahmad
  • 58,947
  • 17
  • 107
  • 133
  • Many thanks @Ahmad How did you find that link? Is your Google-Fu better than mine? – Christopher Perry Oct 30 '13 at 20:58
  • I traced the creation of the actual font in `TextView` all the way down to the point of no return, and found no mapping. There are calls into native code. – Christopher Perry Oct 30 '13 at 21:00
  • 2
    Haha :D I actually knew about the site before that, so finding it wasn't difficult. But for future reference: I prefer to use the search on developer.android.com over the google search, since you can limit the search to only the API's, blog posts, release notes etc. – Ahmad Oct 30 '13 at 22:50
  • 8
    And if you are interested: [This](https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/data/fonts/system_fonts.xml) is where the fonts are defined. [This class](https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/FontLoader.java) loads the fonts and [this one](https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java) manages them afaict. – Ahmad Oct 30 '13 at 23:06
  • By the way, older versions of [Calligraphy](https://github.com/chrisjenx/Calligraphy) use the fontFamily tag to define custom fonts via their filename directly which *could* be what the OP saw in their code. – vinc3m1 Aug 12 '14 at 16:23
  • What's the default one that is used? Also, what's "Roboto-medium" as shown here: http://commondatastorage.googleapis.com/androiddevelopers/design/Roboto_Specimen_Book_20131031.pdf ? – android developer Jan 29 '15 at 15:23
  • @androiddeveloper Ah yes, thanks for that! Reboto Medium and Roboto Black have been added in Roboto V2 that came out with Android Lollipop, as it can be seen in the [diff](https://github.com/android/platform_frameworks_base/commit/d0769f6981ab8eea039a9516bbc37c8fbacfd545#diff-eddd3df16ecaba63bd2858a059863c19). As to what the default font is: it's Roboto Regular. – Ahmad Jan 29 '15 at 23:16
  • @Ahmad What's Roboto-Black? How come a color is a part of the name? Odd. Anyway, can you please add a tiny info for each of the fonts, as to on which API it got added? Also maybe write that the default one is "Roboto-Regular" . – android developer Jan 29 '15 at 23:29
  • 1
    @androiddeveloper done. Roboto black does not refer to the color of the font, but is just a "more bolder" version of of Roboto Bold. I've added a reference image at the bottom. – Ahmad Jan 29 '15 at 23:37
  • 1
    @Ahmad Thank you for clarifying this. Here's your +1 ... :) – android developer Jan 30 '15 at 12:25
  • @Ahmad Why does "Black" also have "italic" (meaning you named it "Black Italic") ? it doesn't seem italic to me... Also, why do you have "Condensed regular"? it's named just "Condensed", no? – android developer Feb 01 '15 at 09:32
  • 2
    also, there is a lot of alias to use with fontFamily https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/fonts.xml – Pauland Mar 25 '15 at 14:16
  • what about roboto-condensed-light ? Can't find since which platform it's available. Can't Google document that properly somewhere ?? – gbero Aug 12 '15 at 08:30
  • way to use these in API : 14 ? android:fontFamily="sans-serif-thin" android:textStyle="normal" – Abdul Wahab Oct 19 '15 at 05:43
  • @abdulwahab Include them in your assets and apply the dont to your textviews. – Ahmad Oct 19 '15 at 12:24
  • Im using sans-serif-light on my app. My photo me is KitKat and m friends is lollipop. When I tested the app on theirs the font was different. Thicker then the sans-serif-light! How can I make it light on all phones? – SmiffyKmc Nov 24 '15 at 11:05
  • 1
    @Smiffy Some manufacturers use custom fonts instead of Roboto, iirc Samsung for example. You would have to include the Roboto in your assets folder and set the font to your TextView, if you really want it to be the same on every device. – Ahmad Nov 24 '15 at 12:14
  • 1
    @Ahmad *sigh* manufactures making our job harder :(. But I'm really happy now as I know what to do :)!! Thanks Ahmad! – SmiffyKmc Nov 24 '15 at 12:19
  • @Smiffy Oh yeah! especially Samsung :/ No problem! – Ahmad Nov 24 '15 at 12:36
  • @Ahmad haha that's funny as that is the device I'm having the problem with xD. Thanks again :) – SmiffyKmc Nov 24 '15 at 12:40
  • Are there any new available fonts to use on Nougat ? – android developer Dec 26 '16 at 20:53
  • sans-serif-light italic|bold also works even though I have not seen it mentioned anywhere – Muhammad Ahmed AbuTalib Feb 21 '18 at 09:00
  • Replace "TextView" with "android.support.v7.widget.AppCompatTextView". Replace "android:fontFamily" with "app:fontFamily". It will work below 16. – Ahamadullah Saikat Jul 02 '18 at 10:45
118

Available fonts (as of Oreo)

Preview of all fonts

The Material Design Typography page has demos for some of these fonts and suggestions on choosing fonts and styles.

For code sleuths: fonts.xml is the definitive and ever-expanding list of Android fonts.


Using these fonts

Set the android:fontFamily and android:textStyle attributes, e.g.

<!-- Roboto Bold -->
<TextView
    android:fontFamily="sans-serif"
    android:textStyle="bold" />

to the desired values from this table:

Font                     | android:fontFamily          | android:textStyle
-------------------------|-----------------------------|-------------------
Roboto Thin              | sans-serif-thin             |
Roboto Light             | sans-serif-light            |
Roboto Regular           | sans-serif                  |
Roboto Bold              | sans-serif                  | bold
Roboto Medium            | sans-serif-medium           |
Roboto Black             | sans-serif-black            |
Roboto Condensed Light   | sans-serif-condensed-light  |
Roboto Condensed Regular | sans-serif-condensed        |
Roboto Condensed Medium  | sans-serif-condensed-medium |
Roboto Condensed Bold    | sans-serif-condensed        | bold
Noto Serif               | serif                       |
Noto Serif Bold          | serif                       | bold
Droid Sans Mono          | monospace                   |
Cutive Mono              | serif-monospace             |
Coming Soon              | casual                      |
Dancing Script           | cursive                     |
Dancing Script Bold      | cursive                     | bold
Carrois Gothic SC        | sans-serif-smallcaps        |

(Noto Sans is a fallback font; you can't specify it directly)

Note: this table is derived from fonts.xml. Each font's family name and style is listed in fonts.xml, e.g.

<family name="serif-monospace">
    <font weight="400" style="normal">CutiveMono.ttf</font>
</family>

serif-monospace is thus the font family, and normal is the style.


Compatibility

Based on the log of fonts.xml and the former system_fonts.xml, you can see when each font was added:

  • Ice Cream Sandwich: Roboto regular, bold, italic, and bold italic
  • Jelly Bean: Roboto light, light italic, condensed, condensed bold, condensed italic, and condensed bold italic
  • Jelly Bean MR1: Roboto thin and thin italic
  • Lollipop:
    • Roboto medium, medium italic, black, and black italic
    • Noto Serif regular, bold, italic, bold italic
    • Cutive Mono
    • Coming Soon
    • Dancing Script
    • Carrois Gothic SC
    • Noto Sans
  • Oreo MR1: Roboto condensed medium
Newtonx
  • 3,095
  • 2
  • 20
  • 12
  • 2
    how did you find on the log about the Android version ? – android developer Feb 01 '15 at 10:17
  • 4
    @androiddeveloper I was looking at the dates when each line was added. To know precisely which fonts are available in a particular version, look at system_fonts.xml for that version, e.g. for Lollipop: https://android.googlesource.com/platform/frameworks/base/+/lollipop-release/data/fonts/system_fonts.xml – Newtonx Feb 05 '15 at 01:27
  • My one and only gripe about this is it is not alphabetized :p But still! This should be the best answer! Thank you! – T.Woody Sep 08 '18 at 04:42
9

As far as I'm aware, you can't declare custom fonts in xml or themes. I usually just make custom classes extending textview that set their own font on instantiation and use those in my layout xml files.

ie:

public class Museo500TextView extends TextView {
    public Museo500TextView(Context context, AttributeSet attrs) {
        super(context, attrs);      
        this.setTypeface(Typeface.createFromAsset(context.getAssets(), "path/to/font.ttf"));
    }
}

and

<my.package.views.Museo900TextView
        android:id="@+id/dialog_error_text_header"
        android:layout_width="190dp"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textSize="12sp" />
Ahmad
  • 58,947
  • 17
  • 107
  • 133
trippedout
  • 1,483
  • 12
  • 18