Android EditText文本颜色始终为白色 [英] Android EditText Text Color is always white

查看:886
本文介绍了Android EditText文本颜色始终为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题确实令人发疯.
由于某种原因,自定义主题中EditText组件的textColor属性未生效.

I have an issue that's truly maddening.
For some reason the textColor attribute for the EditText component in my custom theme is not taking effect.

请注意,我自定义主题的其他所有功能都在起作用,只是'textColor'部分给您带来了麻烦.

我见过其他人也遇到同样的问题,而他们的解决方案"对我不起作用.

I've seen other people with the same issue, and their 'solutions' aren't working for me.

[发布此文章之前引用的文章]
对于AppCompatActivity,TextView颜色始终为白色
appcompat 22.2中的编辑文本颜色为白色

[Articles referenced before posting this]
TextView color is always white for AppCompatActivity
Edittext color is white in appcompat 22.2

[我的代码和设置]

[My Code and Setup]

Android Studio版本 2.1.1

CustomTheme XML代码段

<style name="CustomTheme" parent="@style/AppTheme">
  <item name="editTextStyle">@style/CustomEditText</item> <!-- I'm extending AppCompatActivity, hence no 'android:' prefix! -->
</style>

<style name="CustomEditText" parent="@android:style/Widget.EditText">
    <item name="android:background">@drawable/custom_edit_text</item>
    <item name="android:textColor">#333333</item>
    <item name="android:paddingLeft">12dp</item>
    <item name="android:paddingRight">12dp</item>
    <item name="android:paddingTop">8dp</item>
    <item name="android:paddingBottom">8dp</item>
</style>

Android清单XML代码段

<application android:theme="@style/CustomTheme">...</application>

build.gradle(应用程序)代码段

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.3"

  defaultConfig {
    minSdkVersion 18
    targetSdkVersion 23
  }
}

dependencies {
  compile 'com.android.support:appcompat-v7:23.1.1' <!-- I've even tried this version v7:23.4.0 -->
}

预先感谢您的帮助.

推荐答案

基于 youzking 的评论a>索要活动布局的副本.我看到我在活动的布局xml中将'textColor'设置为白色.因此,这就是问题所在,因为它覆盖了主题"textColor".

Based on a comment by youzking asking for a copy of the activity layout. I saw that I was setting the 'textColor' to white in the layout xml for the Activity. Hence, that was the issue as it was overriding the theme 'textColor'.

这篇关于Android EditText文本颜色始终为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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