Set custom typeface on Hint, TextInputLayout
Asked Answered
P

1

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;
                }
            }
        }
Photochromy answered 8/9, 2016 at 14:35 Comment(0)
B
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;
            }
        }
    }
Bisectrix answered 30/9, 2016 at 0:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.