0
votes

I browsed "/system/fonts" folder on 3 of my Android devices (SGS6, SGS20, H10), downloaded all files from there to my PC, analyzed it and found that some font names are common for all 3 devices - AndroidClock, Carrois Gothic SC, Coming Soon, Cutive Mono, Dancing Script, Droid Sans Mono, Noto Naskh, Noto Sans, Noto Serif, Roboto, Roboto Black, Roboto Condensed, Roboto Condensed Light, Roboto Light, Roboto Medium, Roboto Thin.

The question - is it possible to use any of these in my Xamarin app without bunding them explicitly? It would be nice if I just to specify myLabel.FontFamily = "Coming Soon" and that works... but in real that does not work at all. :-( So, I'm a bit puzzled - why? And if possible to make it working somehow?...

I tried to display 10 labels in my Xamarin app all with different FontFamily names: AndroidClock, Carrois Gothic SC, Coming Soon, Cutive Mono, Dancing Script, Droid Sans, Droid Serif, Droid Sans Mono - but all labels are displayed with the same font (I even not sure what is the name of that default font).

I need it work only for Android. Not interested in iOS at all. Is there a way to tell Xamarin to use only available system fonts on device?

2

2 Answers

1
votes

It would be nice if I just to specify myLabel.FontFamily = "Coming Soon" and that works... but in real that does not work at all. :-( So, I'm a bit puzzled - why? And if possible to make it working somehow?...

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              ║
╚════╩════════════════════════════╩═════════════════════════════╝

Therefore, the ComingSoon.ttf is called as casual in FontFamily.

<Label Text="Hello monospace!"
        FontFamily="monospace"
        HorizontalOptions="CenterAndExpand" />
<Label Text="ComingSoon"
        HorizontalOptions="CenterAndExpand"
        FontFamily="casual"/>
<Label Text="Roboto Black"
        HorizontalOptions="CenterAndExpand"
        FontFamily="sans-serif-black"/>
<Label Text="Default Font"
        HorizontalOptions="CenterAndExpand" />

The effect:

enter image description here

Here is the related discuusion.

1
votes

from Fonts in Xamarin Forms

Controls that display text can set the FontFamily property to a font family name, such as "Times Roman". However, this will only work if that font family is supported on the particular platform.

There are a number of techniques that can be used to attempt to derive the fonts that are available on a platform. However, the presence of a TTF (True Type Format) font file does not necessarily imply a font family, and TTFs are often included that are not intended for use in applications. In addition, the fonts installed on a platform can change with platform version. Therefore, the most reliable approach for specifying a font family is to use a custom font.