在Hint,TextInputLayout上设置自定义字体

Rob*_*eel 6 android xamarin textinputlayout

我试图设置自定义字体上HintTextInputLayout.因此我使用自TextInputLayout定义属性的自定义子类MyHint.此属性设置器应格式化文本并设置FormattedText但不起作用.

如果我只是设置FormattedHint属性它也不格式化.有谁为什么这些方法失败了?

下面你可以看到我的自定义类属性.

例:

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

类:

   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;
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

jgo*_*SFT 0

我想你需要使用:

userNameInput.Typeface = yourCustomTypeFace;
Run Code Online (Sandbox Code Playgroud)

我认为这个属性对你的子类没有多大好处,尽管你当然可以这样做:

public class BaseTextInputLayout: TextInputLayout
{
    public string MyHint
    {
        get
        {
            return Hint;
        }
        set { 
            if (value != null)
            {
                this.Typeface = yourCustomTypeFace;
                this.Hint = value;
            }
            else
            {
                this.Hint = null;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)