Search code examples
xamarinxamarin.formsprism

Custom font not displaying on Android with Xamarin Forms and Prism


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


Solution

  • 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).