I seem to be experiencing a bug with FontFamily in Android. As long as the text ion my label is hard-coded in the label, my custom renderer renders the provided FontFamily just fine. However, if I have the label's TextProperty bound, the font never makes it to the final screen.
Has anyone else experienced any issues with FontFamily?
This is a big one for us on our side. I'd greatly appreciate any feedback from Xamarin or workarounds from the community.
Here's my working Android custom renderer:
[assembly: ExportRenderer(typeof(Label), typeof(CustomLabelRenderer))]
namespace Aria.Droid.Controls
{
public class CustomLabelRenderer : LabelRenderer {
protected override void OnElementChanged (ElementChangedEventArgs<Label> e) {
base.OnElementChanged (e);
var fontFamily = e.NewElement.FontFamily;
if (!string.IsNullOrEmpty(fontFamily))
{
if (!fontFamily.Contains(".ttf")) fontFamily += ".ttf";
var typeface = Typeface.CreateFromAsset(Forms.Context.Assets, fontFamily);
var label = ((TextView)Control);
label.Typeface = typeface;
}
}
}
}