6

I'm trying to set a custom typeface on the Hint of a TextInputLayout. Therefore I'm using a custom subclass of TextInputLayout with a custom property MyHint. This property setter should format the text and set the FormattedText but it doesn't work.

If I simply set the FormattedHint property it also doesn't format. Does anyone why these approaches are failing?

Below you can see my custom class with property.

Example:

BaseTextInputLayout userNameInput = view.FindViewById<BaseTextInputLayout>(Resource.Id.myId);
userNameInput.MyHint = "My Custom hint text";

Class:

   public class BaseTextInputLayout: TextInputLayout
    {
        public string MyHint
        {
            get
            {
                return Hint;
            }
            set { 
                if (value != null)
                {
                    SpannableStringBuilder builder = new SpannableStringBuilder(value);
                    builder.SetSpan(new CustomTypeFaceSpan("", Constants_Android.TYPEFACE_YOGA_MET_EVY_CUSTOMFONT), 0, builder.Length(), SpanTypes.InclusiveExclusive);
                    this.HintFormatted = builder;
                }
                else
                {
                    this.HintFormatted = null;
                }
            }
        }
vrwim
  • 13,020
  • 13
  • 63
  • 118
Robin Bruneel
  • 1,063
  • 8
  • 22

1 Answers1

0

I think you will need to use:

userNameInput.Typeface = yourCustomTypeFace;

I don't see much benefit to your sub-class with this property, though you could certainly do:

public class BaseTextInputLayout: TextInputLayout
{
    public string MyHint
    {
        get
        {
            return Hint;
        }
        set { 
            if (value != null)
            {
                this.Typeface = yourCustomTypeFace;
                this.Hint = value;
            }
            else
            {
                this.Hint = null;
            }
        }
    }
jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44