Android:EditText的android:textAppearance中的textColor被忽略 [英] Android: textColor ignored in android:textAppearance of the EditText
问题描述
通过自定义textAppearance
样式设置textColor
属性时,是否有任何原因会被忽略?
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>
以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.
设置颜色的唯一方法是在EditText
中设置textColor
属性(但这不是我想要的):
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"
/>
请注意,为TextView
创建的带有textColor
的自定义textAppearance
可以正常工作.
Note, custom textAppearance
with textColor
created for TextView
works without problem.
我试图用android.support.v7.widget.AppCompatEditText
或android.support.design.widget.TextInputEditText
替换EditText
,但结果是相同的.还是行不通.因此问题不在EditText
实现中.
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.
我发现了同样问题的问题为什么android:textAppearance中的textColor被忽略了?.不幸的是,没有答案.
I found question with the same problem Why is textColor in android:textAppearance ignored?. Unfortunately, without answer.
推荐答案
沿线的某个地方,正在拾取并应用textColor
的错误/默认值.您可以通过在XML中为EditText
设置android:textColor="@null"
来强制使用在android:textAppearance
中定义的android:textColor
.
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
.
这篇关于Android:EditText的android:textAppearance中的textColor被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!