Valid Values for Android:Fontfamily and What They Map To

Valid values for android:fontFamily and what they map to?


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:

How to change fontFamily of TextView in Android

From android 4.1 / 4.2 / 5.0, 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-black" // roboto black
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)

Sample Image

in combination with

android:textStyle="normal|bold|italic"

this 16 variants are possible:

  • Roboto regular
  • Roboto italic
  • Roboto bold
  • Roboto bold italic
  • Roboto-Light
  • Roboto-Light italic
  • Roboto-Thin
  • Roboto-Thin italic
  • Roboto-Condensed
  • Roboto-Condensed italic
  • Roboto-Condensed bold
  • Roboto-Condensed bold italic
  • Roboto-Black
  • Roboto-Black italic
  • Roboto-Medium
  • Roboto-Medium italic

fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="font_family_light">sans-serif-light</string>
<string name="font_family_medium">sans-serif-medium</string>
<string name="font_family_regular">sans-serif</string>
<string name="font_family_condensed">sans-serif-condensed</string>
<string name="font_family_black">sans-serif-black</string>
<string name="font_family_thin">sans-serif-thin</string>
</resources>

What is the default font family in Android?

There is no documentation on d.android.com for font family names. However, if you look at AOSP, the default fonts are loaded in android.graphics.*. The FontListParser loads the default fonts from /system/etc/fonts.xml (Android 5.0+) or /system/etc/system_fonts.xml (Android 4.1). The default fonts are loaded in Typeface#init.

The two XML files have some documentation. The first font is the default font. You can pull /system/etc/fonts.xml from your device. A device manufacturer or custom ROM may change the default system fonts.

fonts.xml (API 21+)

NOTE: this is the newer (L) version of the system font configuration,
supporting richer weight selection. Some apps will expect the older
version, so please keep system_fonts.xml and fallback_fonts.xml in sync
with any changes, even though framework will only read this file.

All fonts withohut names are added to the default list. Fonts are chosen
based on a match: full BCP-47 language tag including script, then just
language, and finally order (the first font containing the glyph).

Order of appearance is also the tiebreaker for weight matching. This is
the reason why the 900 weights of Roboto precede the 700 weights - we
prefer the former when an 800 weight is requested. Since bold spans
effectively add 300 to the weight, this ensures that 900 is the bold
paired with the 500 weight, ensuring adequate contrast.

system_fonts.xml (API 16-20)

System Fonts

This file lists the font families that will be used by default for all supported glyphs.
Each entry consists of a family, various names that are supported by that family, and
up to four font files. The font files are listed in the order of the styles which they
support: regular, bold, italic and bold-italic. If less than four styles are listed, then
the styles with no associated font file will be supported by the other font files listed.

The first family is also the default font, which handles font request that have not specified
specific font names.

Any glyph that is not handled by the system fonts will cause a search of the fallback fonts.
The default fallback fonts are specified in the file /system/etc/fallback_fonts.xml, and there
is an optional file which may be supplied by vendors to specify other fallback fonts to use
in /vendor/etc/fallback_fonts.xml.

If you parse the fonts.xml file, you can find which font family uses which typeface (see here):

╔════╦════════════════════════════╦═════════════════════════════╗
║ ║ FONT FAMILY ║ TTF FILE ║
╠════╬════════════════════════════╬═════════════════════════════╣
║ 1 ║ casual ║ ComingSoon.ttf ║
║ 2 ║ cursive ║ DancingScript-Regular.ttf ║
║ 3 ║ monospace ║ DroidSansMono.ttf ║
║ 4 ║ sans-serif ║ Roboto-Regular.ttf ║
║ 5 ║ sans-serif-black ║ Roboto-Black.ttf ║
║ 6 ║ sans-serif-condensed ║ RobotoCondensed-Regular.ttf ║
║ 7 ║ sans-serif-condensed-light ║ RobotoCondensed-Light.ttf ║
║ 8 ║ sans-serif-light ║ Roboto-Light.ttf ║
║ 9 ║ sans-serif-medium ║ Roboto-Medium.ttf ║
║ 10 ║ sans-serif-smallcaps ║ CarroisGothicSC-Regular.ttf ║
║ 11 ║ sans-serif-thin ║ Roboto-Thin.ttf ║
║ 12 ║ serif ║ NotoSerif-Regular.ttf ║
║ 13 ║ serif-monospace ║ CutiveMono.ttf ║
╚════╩════════════════════════════╩═════════════════════════════╝

How to set default font family for entire Android app

The answer is yes.

Global Roboto light for TextView and Button classes:

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:buttonStyle">@style/RobotoButtonStyle</item>
</style>

<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>

<style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
<item name="android:fontFamily">sans-serif-light</item>
</style>

Just select the style you want from list themes.xml, then create your custom style based on the original one. At the end, apply the style as the theme of the application.

<application
android:theme="@style/AppTheme" >
</application>

It will work only with built-in fonts like Roboto, but that was the question. For custom fonts (loaded from assets for example) this method will not work.

EDIT 08/13/15

If you're using AppCompat themes, remember to remove android: prefix. For example:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="buttonStyle">@style/RobotoButtonStyle</item>
</style>

Note the buttonStyle doesn't contain android: prefix, but textViewStyle must contain it.

How to create custom font family with bold font

Set 700 as the fontWeight value for your font in bold.

As it's in the font resources documentation:

The most common values are 400 for regular weight and 700 for bold
weight.

In the lobster font family example you linked it would be:

<!-- bold -->
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/lobster_bold" />

And, if you are using support lib:

<!-- bold -->
<font
app:font="@font/lobster_bold"
app:fontStyle="normal"
app:fontWeight="700" />

How to change fontFamily of TextView in Android

From android 4.1 / 4.2 / 5.0, 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-black" // roboto black
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)

Sample Image

in combination with

android:textStyle="normal|bold|italic"

this 16 variants are possible:

  • Roboto regular
  • Roboto italic
  • Roboto bold
  • Roboto bold italic
  • Roboto-Light
  • Roboto-Light italic
  • Roboto-Thin
  • Roboto-Thin italic
  • Roboto-Condensed
  • Roboto-Condensed italic
  • Roboto-Condensed bold
  • Roboto-Condensed bold italic
  • Roboto-Black
  • Roboto-Black italic
  • Roboto-Medium
  • Roboto-Medium italic

fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="font_family_light">sans-serif-light</string>
<string name="font_family_medium">sans-serif-medium</string>
<string name="font_family_regular">sans-serif</string>
<string name="font_family_condensed">sans-serif-condensed</string>
<string name="font_family_black">sans-serif-black</string>
<string name="font_family_thin">sans-serif-thin</string>
</resources>

What fonts are installed by default on Android?

There are only three system wide fonts in Android;

1 normal (Droid Sans),

2 serif (Droid Serif),

3 monospace (Droid Sans Mono).

Applications can install fonts for themselves, but not for system-wide use.

For more you can see List of fonts included with each device link

and

Since the Ice Cream Sandwich release, Roboto has been the standard typeface on Android.

Since Froyo, Noto has been the standard typeface on Android for all languages not covered by Roboto. Noto is also the standard typeface for all languages on Chrome OS.

Refer here



Related Topics



Leave a reply



Submit