I use android support library, which version I don not know because I do not know of a way how to check it. The problem I am facing that apparently the value for android:textColor attribute is ignored. If I define a style and assign it to textAppearance of EditText the color textColor is ignored.
So, I have a following layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- This text should be red, but it is black -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text color via TextAppearance"
android:textAppearance="@style/TextAppearance.EditText" />
<!-- The hint should be green, but it is grey -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint color via TextAppearance"
android:textAppearance="@style/TextAppearance.EditText" />
<!-- Text is red as set in android:textColor -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text color via android:textColor"
android:textColor="#880000"
android:textSize="18sp" />
<!-- Hint is green as set in android:textColorHint -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint color via android:textColorHint"
android:textColorHint="#008800"
android:textSize="18sp" />
</LinearLayout>
I have defined the following style:
<!-- Text Appearance -->
<style name="TextAppearance.EditText" parent="">
<item name="android:textColor">#880000</item> <!-- this color is ignored -->
<item name="android:textColorHint">#008800</item> <!-- this color is ignored -->
<item name="android:textSize">18sp</item>
</style>
Is this a bug in support library or did I miss something?
Somewhere along the line, the wrong/default value for
textColor
is being picked up and applied. You can force theandroid:textColor
that you define inandroid:textAppearance
to be used by settingandroid:textColor="@null"
in your XML forEditText
. This should work forandroid:textColorHint
as well.(This reflects the accepted answer to this post.)
Use
style="@style/TextAppearance.EditText"
instead of
android:textAppearance="@style/TextAppearance.EditText"
It should work!