About Android Fonts - aMarCruz/react-native-text-size GitHub Wiki
Android does not offer functions to enumerate the pre-installed fonts and the official names are aliased to real font names, so the information provided by the rnTextSize fontFamilyNames
function is hardcoded and limited to a subset of fonts that you will (probably) find already installed.
For example, in devices with API 21 or above, the system fonts are:
Generic Name | Font File (.ttf) | Weight | Italic |
---|---|---|---|
sans-serif-thin | Roboto-Regular (aliased)Roboto-ThinItalic | 100 | yes |
sans-serif-light | Roboto-LightRoboto-LightItalic | 300 | yes |
sans-serif | Roboto-RegularRoboto-RegularItalic | 400 | yes |
Roboto-BoldRoboto-BoldItalic | 700* | yes | |
sans-serif-medium | Roboto-MediumRoboto-MediumItalic | 500 | yes |
sans-serif-black | Roboto-BlackRoboto-BlackItalic | 900 | yes |
sans-serif-condensed-light | RobotoCondensed-LightRobotoCondensed-LightItalic | 300 | yes |
sans-serif-condensed | RobotoCondensed-RegularRobotoCondensed-Italic | 400 | yes |
RobotoCondensed-BoldRobotoCondensed-BoldItalic | 700* | yes | |
sans-serif-smallcaps | CarroisGothicSC-Regular | 400 | -- |
serif | NotoSerif-RegularNotoSerif-RegularItalic | 400 | yes |
NotoSerif-BoldNotoSerif-BoldItalic | 700* | yes | |
monospace | DroidSansMono | 400 | -- |
serif-monospace | CutiveMono | 400 | -- |
casual | ComingSoon | 400 | -- |
cursive | DancingScript-Regular | 400 | -- |
DancingScript-Bold | 700* | -- |
* There is not *-bold
generic names of this fonts, to obtain the weight 700 of them, you must use fontWeight: 'bold'
.
Up to SDK 27, Android did not support setting different weights other than 'normal' and 'bold' by code. RN 0.57, the last version released on this date, does not support it either and converts weights '500'-'900' to 'bold'.
So, for example, if you want "Roboto Medium Italic" (weight 500), you have only two choices:
// recommended
{
fontFamily: 'sans-serif-medium',
fontStyle: 'italic'
}
// by filename ...looks more like an iOS font face :)
{
fontFamily: 'Roboto-MediumItalic'
}
But for "Roboto Bold Italic", you can use any of this forms:
// recommended
{
fontWeight: 'bold',
fontStyle: 'italic'
}
// generic name, specific weight & style
{
fontFamily: 'sans-serif',
fontWeight: 'bold',
fontStyle: 'italic'
}
// by filename, with embedded weight & style
{
fontFamily: 'Roboto-BoldItalic'
}
Also, be careful not to overwrite the desired weight with fontWeight
, as here:
{
fontFamily: 'sans-serif-medium',
fontStyle: 'bold' // bye bye weight 500
}
Some of the predefined, alternative names:
- sans-serif: arial, helvetica, tahoma, verdana.
- serif: times, times new roman, palatino, georgia, baskerville, goudy, fantasy, ITC Stone Serif
- monospace: sans-serif-monospace, monaco
- serif-monospace: courier, courier new
If you are curious, se the fonts.xml
or system_fonts.xml
file in the ~/Android/Sdk/platforms/android-[sdk-num]/data/fonts directory.