4

I'm having a problem on an specific device, the HTC EVO on Android 2.3.x. I think this may be a HTC Sense-specific problem.

I basically have an EditText with a transparent background (#00000000) and white text, set to allow an email address input (inputType is textEmailAddress).

Problem:When the user is writing the email address, however, text is black, thus impossible to read.

When the user changes focus to another view element, the text is correctly colored back to white.

If the user focuses back on the EditText, the text previously entered is still white, but any new text is black.

If I change the inputType from textEmailAddress, to say, nothing, or textFilter, text is rendered correctly... it's still black, but it has a highlight around it (due to the "suggestions" provided by the keyboard - not shown on textEmailAddress type.) and therefore, it's readable. The downside is not having the email input method (with "@" on the keyboard).

I'd like my text to just be always readable (that is, white when writing) and to have the proper (email) entry. Suggestions or not, it doesn't matter - it just has to be readable.

The EditText used is simple enough:

<EditText
    android:id="@+id/fieldEmail"
    android:layout_width="match_parent"
    android:layout_height="42dp"
    android:layout_marginTop="10dp"
    android:hint="Enter your email"
    android:textSize="16dp"
    android:textColor="#ffffffff"
    android:textColorHint="#ffffffff"
    android:textColorLink="#ffffffff"
    android:background="#00000000"
    android:inputType="textEmailAddress">
</EditText>

Any suggestions? I tried several things, including changing all kinds of colors (in case it's trying to "guess" the text color for selection highlight) and nothing works; there's no way to set the color of the text being written... it's always black.

zeh
  • 10,130
  • 3
  • 38
  • 56

2 Answers2

4

I'd like to add a small comment here - using Spannable.SPAN_EXCLUSIVE_EXCLUSIVE in some cases can cause:

IndexOutOfBoundsException: setSpan(...

to avoid that simply we have to choose different span flag, for me works Spannable.SPAN_COMPOSING.

I was getting mentioned exception when I was editing text in EditText view and I received an incoming call. Also in situation when I was editing the text in the middle and then I tried to add a character on the end (only on devices with HTC Sense version < 2.1).

Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121
theb1uro
  • 536
  • 1
  • 4
  • 8
3

I've experienced the same thing on some HTCs. I implemented a TextWatcher to force the text color as a Spannable as you type in the EditText

    private class HTCEditTextFix implements TextWatcher {
        private EditText mEditText;
        public HTCEditTextFix(EditText editText) {
            mEditText = editText;
        }
        public void afterTextChanged(Editable s) {}
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mEditText.getText().setSpan(new ForegroundColorSpan(Color.WHITE), start, start, Spannable.SPAN_COMPOSING);
        }
    }

Then apply it to your EditText

myEditText1.addTextChangedListener(new HTCEditTextFix(myEditText1));
gdub
  • 793
  • 9
  • 16
  • The closest to a solution. Haven't tried it personally but looks good enough. Thanks. – zeh Dec 03 '12 at 20:04