1
votes

Developing an app for iOS and Android with Xamarin Forms (2.3.1) and Prism (6.2) we've had difficulty getting custom fonts to work on Android but iOS has been fine.

We have followed the most recent documentation (i.e. not using custom renders) and seem to have narrowed it to being related to Prism...

To simplify the problem we made a new Forms App, added the Lobster-Regular.ttf from the Xamarin demo to Android Assets and iOS Resources and ensured its property was AndroidAsset and BundleResource respectively, then in the default xaml page added:

    <Label Text="Hello Forms with XAML">
        <Label.FontFamily>
            <OnPlatform x:TypeArguments="x:String">
                <OnPlatform.iOS>MarkerFelt-Thin</OnPlatform.iOS>
                <OnPlatform.Android>Lobster-Regular.ttf#Lobster-Regular</OnPlatform.Android>
                <OnPlatform.WinPhone></OnPlatform.WinPhone>
            </OnPlatform>
        </Label.FontFamily>
    </Label> 

(That's also straight from the demo)

It works for both iOS and Android.

If we create a new Prism Unity App, add the font file, check the properties (which default correctly) and insert the label in MainPage.xaml iOS will use the custom font but Android will just use the standard font.

There is a known issue with custom fonts in UWP and WP apps but this doesn't seem related.

All testing has been on the iOS simulator and the Android Emulator.

Update As per Dan S.'s comment I've uploaded a project to show a minimal prism app with the custom font that works in iOS but not Android: sample project

2
can you provide a sample demonstrating the issue? Prism shouldn't have any effect one way or another on something like displaying a custom font.Dan Siegel
I've uploaded a project to demonstrate it and yes I agree Prism shouldn't have an impact but as I say I tried to narrow it down and the steps work for a non Prism app and with a Prism app iOS works nut not Android ¯_(ツ)_/¯Paddy

2 Answers

1
votes

Based on the solution you provided, the problem appears to be with the version of Xamarin Forms you are using in your project. Your sample uses X.F 2.3.1.114, the sample from Xamarin uses 2.3.3.180. Updating to at least 2.3.3.180 resolves the issue in your sample. Updating to Prism 6.3.0-pre2 also works (but only because it updates Xamarin Forms to the latest release).

1
votes

This problem was driving me insane because no matter what I tried, the font would show up in my UWP application, but not in my Android application.

I found the solution however. As stupid as this is, if the font file itself is named "MyFont.TTF" and not "MyFont.ttf" (note the difference in capitalization of the file extension), no errors occur in the Android app, but the font doesn't show up. When I changed the case of the file extension to lower case, rebuilt, and redeployed, as if by magic, the font showed up!

Hope someone else reads this post and it helps them get over this silly hurdle...