private void UpdateFormattedText() { if (Element?.FormattedText == null) { return; } var extensionType = typeof(FormattedStringExtensions); var type = extensionType.GetNestedType("FontSpan", BindingFlags.NonPublic); var ss = new SpannableString(Control.TextFormatted); var spans = ss.GetSpans(0, ss.ToString().Length, Class.FromType(type)); foreach (var span in spans) { var font = (Font)type.GetProperty("Font").GetValue(span, null); if ((font.FontFamily ?? Element.FontFamily) != null) { var start = ss.GetSpanStart(span); var end = ss.GetSpanEnd(span); var flags = ss.GetSpanFlags(span); ss.RemoveSpan(span); var typeFace = FindFont(font.FontFamily); var newSpan = new CustomTypefaceSpan(typeFace); ss.SetSpan(newSpan, start, end, flags); } } Control.TextFormatted = ss; }
private void UpdatePlaceholderFont() { if (CustomElement.AltFontFamily == default) { Control.HintFormatted = null; Control.Hint = CustomElement.Placeholder; Control.SetHintTextColor(CustomElement.PlaceholderColor.ToAndroid()); return; } var placeholderFontSize = (int)CustomElement.FontSize; var placeholderSpan = new SpannableString(CustomElement.Placeholder); placeholderSpan.SetSpan(new AbsoluteSizeSpan(placeholderFontSize, true), 0, placeholderSpan.Length(), SpanTypes.InclusiveExclusive); // Set Fontsize var typeFace = FindFont(CustomElement.AltFontFamily); var typeFaceSpan = new CustomTypefaceSpan(typeFace); placeholderSpan.SetSpan(typeFaceSpan, 0, placeholderSpan.Length(), SpanTypes.InclusiveExclusive); //Set Fontface Control.HintFormatted = placeholderSpan; }