As explained in this blog post and mentioned in the docs, you need to add all the font styles you want. e.g. RobotoCondensed-bold
, RobotoCondensed-regular
and RobotoCondensed-italic
.
Then you can reference them in a platform-specific way. On android, a font that you placed in Assets/Fonts
is referred to by the string Fonts/RobotoCondensed-bold.ttf#RobotoCondensed-bold
where the first part is determined by the filename, and the part after the #
is the PostscriptName of the font.
On iOS, you only need the font name.
FontFamily = Device.RuntimePlatform == Device.iOS ? "Lobster-Regular" : null // set only for iOS
FontFamily = Device.RuntimePlatform == Device.Android ? "Lobster-Regular.ttf#Lobster-Regular" : null // set only for Android
To make referring to fonts easier, you can define a platform-specific style in App.xaml
:
<OnPlatform x:TypeArguments="x:String" x:Key="MyFontRegular">
<On Platform="Android" Value="Fonts/myfont-regular.ttf#MyFont-Regular" />
<On Platform="iOS" Value="MyFont-Regular" />
</OnPlatform>
Set FontFamily="{StaticResource MyFontRegular}"
to apply this font. This effectively deactivates the effects of FontAttributes
set on the same element.
If your font styles are simply the common regular
, bold
and italic
, you can refer to them using FontAttributes
by setting FontFamily="My FontFamily Name"
, where the font family name can be found similarly to how you find the PostscriptName of the font. This option of using the FontAttributes
is something I just stumbled upon, though. I do not know whether this is documented behaviour. And it does not seem to work for other styles like dashed
or medium
. It is also worth pointing out that the result from setting the FontFamily and FontAttributes does not look exactly the same like specifying the exact font with style included. It is possible, that using FontAttributes
makes Xamarin ignore FontFamily
.