Why is textColor in android:textAppearance ignored?

╄→гoц情女王★ 提交于 2019-12-11 04:38:58

问题


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?


回答1:


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. This should work for android:textColorHint as well.

(This reflects the accepted answer to this post.)




回答2:


Use

style="@style/TextAppearance.EditText"

instead of

android:textAppearance="@style/TextAppearance.EditText"

It should work!



来源:https://stackoverflow.com/questions/39548002/why-is-textcolor-in-androidtextappearance-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!