Android:EditText的android:textAppearance中的textColor被忽略 [英] Android: textColor ignored in android:textAppearance of the EditText

查看:188
本文介绍了Android:EditText的android:textAppearance中的textColor被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过自定义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.AppCompatEditTextandroid.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆