Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.3+, android:textColorHint doesn't work, hint color is always white

As the question says: When testing the app on devices running Android 4.3+ (also tested on 4.4), the color of the hints (for EditText) turns white, and no matter what color I set it to, it remains white. Since the EditText's background is white, the hints isn't visible to the naked eye!

I've googled and googled and can't find anyone having the same issue. The app was built using android:minSdkVersion="8" and android:targetSdkVersion="15". The EditText looks like this:

 <EditText
            android:id="@+id/editText3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/my_background"
            android:ems="10"
            android:textColorHint="@color/BlueViolet"
            android:hint="@string/my_hint"
            android:inputType="number"
            android:tag="21_0" />

At first it was using the default android:textColorHint and I thought that maybe Android 4.3+ changed the default to white for some reason. But that doesn't seem to be the case since whatever color I set it to, it's always white.

I'm aware that fill_parent is deprecated, but the app was build quite some time ago, but is now unuseable due to hints disappearing. Any help is appreciated! Thanks!

EDIT: The 'error' seem to occur when using a String-resource for hint. This works: android:hint="Hello world" while this doesn't android:hint="@string/my_hint"

like image 738
Whyser Avatar asked Feb 10 '14 10:02

Whyser


2 Answers

For who struggles with same problem;

If you used your edittext in

android.support.design.widget.TextInputLayout

you should put your

android:textColorHint="@color/BlueViolet"

in TextInputLayout

<android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColorHint="@android:color/white">

                <AutoCompleteTextView
                    android:id="@id/etextEmail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_card"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:textColor="@android:color/white"/>

            </android.support.design.widget.TextInputLayout>
like image 58
Erhan SEN Avatar answered Oct 29 '22 20:10

Erhan SEN


It seems since Android 4.3+ it's no longer possible to make String-resources as follows (not sure if it was ever meant to work this way though):

<string name="my_hint"><font size="13" fgcolor="#ffbbbbbb">Hello world</font></string>

If you do, they turn out white. So you are stuck with creating the String-resource this way:

<string name="my_hint">Hello world</string>

And then use the properties on the TextView/EditText to edit the color of the hint. To change the size, it seems it's still possible to do:

 <string name="my_hint"><small><small>Hello world</small></small></string>

I found this out by reading the comment of this answer: https://stackoverflow.com/a/11577658/2422321, by Edward Falk

like image 33
Whyser Avatar answered Oct 29 '22 20:10

Whyser