示例#1
0
        public static void ApplyTo(this ExtendedFont font, TextView textView)
        {
            if (font == null)
            {
                return;
            }

            if (font.Family == null)
            {
                TypefaceStyle typefaceStyle = TypefaceStyle.Normal;

                switch (font.FontAttributes)
                {
                case FontAttributes.Bold:
                    typefaceStyle = TypefaceStyle.Bold;
                    break;

                case FontAttributes.Italic:
                    typefaceStyle = TypefaceStyle.Italic;
                    break;
                }

                textView.SetTypeface(Typeface.Default, typefaceStyle);
            }
            else
            {
                textView.SetTypeface(TypefaceHelper.GetTypeface(font.Family), TypefaceStyle.Normal);
            }

            textView.SetTextColor(font.Color.ToAndroid());
            textView.SetTextSize(Android.Util.ComplexUnitType.Dip, font.Size);

            if (font.IsUnderlined)
            {
                SpannableString content = new SpannableString(textView.Text);
                content.SetSpan(new UnderlineSpan(), 0, textView.Text.Length, 0);
                textView.TextFormatted = content;
            }

            if (font.LineSpacing != 0)
            {
                textView.SetLineSpacing(font.LineSpacing, 1);
            }
        }
 public CustomTypefaceSpan(ExtendedFont font) : base(font.Family)
 {
     _typeface = TypefaceHelper.GetTypeface(font.Family);
 }