Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: textColor ignored in android:textAppearance of the EditText

Is there any reason why is textColor property being ignored when it is set via custom textAppearance style?

<style name="EditTextAppearance" parent="@android:style/TextAppearance.Widget.EditText">
    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:textSize">16sp</item>
    <item name="android:textColor">@color/blue</item> <!-- IGNORED -->
</style>

Setting style in XML:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@style/EditTextAppearance"
    />

For some reason, default theme control color is not overridden by this style.

The only way how I am able to set color is by setting textColor property in EditText (but this is not what I want):

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@style/EditTextAppearance"
    android:textColor="@color/blue"
    />

Note, custom textAppearance with textColor created for TextView works without problem.

I tried to replace EditText by android.support.v7.widget.AppCompatEditText or android.support.design.widget.TextInputEditText but the result was the same. Still not working. So the problem is not in EditText implementation.

I found question with the same problem Why is textColor in android:textAppearance ignored?. Unfortunately, without answer.

like image 640
matoni Avatar asked Jul 19 '17 16:07

matoni


1 Answers

Somewhere along the line, the wrong/default value for textColor is being picked up and applied. You can force the android:textColor that you define in android:textAppearance to be used by setting android:textColor="@null" in your XML for EditText.

like image 151
Cheticamp Avatar answered Oct 15 '22 18:10

Cheticamp