问题描述
我使用的是android支持库,我不知道哪个版本,因为我不知道如何检查它.我面临的问题显然是android:textColor属性的值被忽略了.如果我定义样式并将其分配给EditText的textAppearance,则将忽略textColor颜色.
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.
所以,我有以下布局:
<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>
我定义了以下样式:
<!-- 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?
推荐答案
沿线的某个地方,正在拾取并应用textColor
的错误/默认值.您可以通过在XML中为EditText
设置android:textColor="@null"
来强制使用在android:textAppearance
中定义的android:textColor
.这同样适用于android:textColorHint
.
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.
(这反映了对此.)
这篇关于为什么android:textAppearance中的textColor被忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!