I\'m trying to build a renderer for Xamarin Forms. The renderer needs to set the EditText
underline color to \"Active Color\" when selected and \"Hint Color\" when
So the solution for me was to go pure AppCompat
So I'm adding an AppCompatEditText
to the TextInputLayout
protected EditText EditText => Control.EditText;
protected override TextInputLayout CreateNativeControl()
{
var textInputLayout = new TextInputLayout(Context);
var editText = new AppCompatEditText(Context)
{
SupportBackgroundTintList = ColorStateList.ValueOf(GetPlaceholderColor())
};
textInputLayout.AddView(editText);
return textInputLayout;
}
Then from there I was able to set the underline consistently with this.
private void ControlOnFocusChange(object sender, FocusChangeEventArgs args)
{
_hasFocus = args.HasFocus;
SetUnderlineColor(_hasFocus ? GetActivePlaceholderColor(): GetPlaceholderColor());
}
private void SetUnderlineColor(AColor color)
{
var element = (ITintableBackgroundView)EditText;
element.SupportBackgroundTintList = ColorStateList.ValueOf(color);
}
full source code here.