/// <summary> /// Applies a custom typeface span to the text. /// </summary> /// <returns>Either the passed in Object or new IEditable with the typeface span applied.</returns> /// <param name="s">text to apply it too.</param> /// <param name="typeface">Typeface to apply.</param> public static IEditable ApplyTypefaceSpan(IEditable s, Typeface typeface) { if (s?.Length() > 0) { s.SetSpan(TypefaceUtils.GetSpan(typeface), 0, s.Length(), SpanTypes.ExclusiveExclusive); } return(s); }
/// <summary> /// Applies a custom typeface span to the text. /// </summary> /// <returns>The passed in string.</returns> /// <param name="s">text to apply it too.</param> /// <param name="typeface">Typeface to apply.</param> public static string ApplyTypefaceSpan(string s, Typeface typeface) { if (!string.IsNullOrEmpty(s)) { SpannableString span = new SpannableString(s); span.SetSpan(TypefaceUtils.GetSpan(typeface), 0, s.Length, SpanTypes.ExclusiveExclusive); } return(s); }
/// <summary> /// Useful for manually fonts to a TextView. Will not default back to font /// set in <see cref="CalligraphyConfig"/> /// </summary> /// <returns><c>true</c>, if font to text view was applyed, <c>false</c> otherwise.</returns> /// <param name="context">Context.</param> /// <param name="textView">Not null, TextView to apply to.</param> /// <param name="filePath">if null/empty will do nothing.</param> /// <param name="deferred">If set to <c>true</c> deferred.</param> public static bool ApplyFontToTextView(Context context, TextView textView, string filePath, bool deferred = false) { if (textView == null || context == null) { return(false); } AssetManager assetManager = context.Assets; Typeface typeface = TypefaceUtils.Load(assetManager, filePath); return(ApplyFontToTextView(textView, typeface, deferred)); }