AlonAviv
AlonAviv

Reputation: 43

AutoCompleteTextView is getting highlighted

I have created a login activity with AutoCompleteTextView components for email and password. Once getting auto completed, these fields are getting highlighted. How do I disable this highlighting? Could not find any relevant property for this one.

form inputs are getting highlighted screenshot

Upvotes: 1

Views: 1096

Answers (2)

AlonAviv
AlonAviv

Reputation: 43

Although it's been a while, I finally found the proper answer. This highlight is due to Android's Autofill Framework.

To override the highlight setting -

  1. SDK min version must be > 26
  2. In app theme (style) add the the following item: android:autofilledHighlight and set the value to whatever color you want (to 'disable' this highlight just set it to transparent).

Upvotes: 3

AlonAviv
AlonAviv

Reputation: 43

Sadly, I couldn't find any solution via design properties (styles/ layout properties etc.).

I had to use a workaround, which is not the prettiest - but got it done:

  1. Added TextChangeListener to relevant EditText:

mPasswordView.addTextChangedListener(textWatcherWorkAround);

  1. Within the Listener, in 'afterTextChanged' overriden method I added:
// til is the TextInputLayout wrapping my EditText
til.setBackground(getResources().getDrawable(android.R.color.transparent));

mPasswordView.removeTextChangedListener(this);
mEmailView.removeTextChangedListener(this); // To avoid infinite loop

String original = mPasswordView.getText().toString();
mPasswordView.setText(original + " ");

mPasswordView.addTextChangedListener(this); // To next time

It ain't pretty, please let me know if you find any, straight-forward, better approach. For now - I hope it helps who ever encountered this one!

Upvotes: 0

Related Questions