How to consistently set EditText Selected Underline Color Programmatically
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);}
Modify your code in XfxEntryRendererDroid
ControlOnFocusChange
method like this :
private void ControlOnFocusChange(object sender, FocusChangeEventArgs args){ _hasFocus = args.HasFocus; if (_hasFocus) { ... EditText.PostDelayed(() => { //Add the following code SetUnderlineColor(GetActivePlaceholderColor()); EditText.RequestFocus(); manager.ShowSoftInput(EditText, 0); }, 0);//Change it to 0 } ...}
Why don't you change the tint colour at runtime using this (May be in your text changed event):
ViewCompat.SetBackgroundTintList(_YourView , ColorStateList.ValueOf(Color.ParseColor(Resources.GetString(Resource.Color.blueLine))));
Anyways Goodluck!