android - Edittext 颜色在 appcompat 22.2 中为白色

标签 android android-design-library android-appcompat

EDIT 2 :这是因为这条线而发生的

<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>

styles.xml .我用它来显示浅色(白色)文本和返回主页按钮 ToolBar .如果我将其更改为 <item name="theme">@style/ThemeOverlay.AppCompat.Light</item>然后EditText按预期工作,但我的 ToolBar文本和返回主页按钮的颜色变为深色(黑色)。

因为我使用深色 ToolBar我想以浅色(白色)显示文本和返回主页按钮。

我尝试使用 <item name="android:theme">...</item>而不是 <item name="theme">...</item>但没有任何帮助,工具栏文本和后退按钮仍然保持深色!有人知道吗?帮帮我!

实际问题:

appcompat-v7:22.2.0 中我用了 EditText .我正在为 Activity 使用以下主题

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/myPrimaryColor</item>
    <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
    <item name="colorAccent">@color/myAccentColor</item>
    <item name="android:windowBackground">@color/myWindowBackground</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="colorControlHighlight">#0000AA</item>
</style>

但是 EditText 的颜色是白色的。底线、提示和文本都是白色的。我听说 AppCompat 中有一个错误但是如何解决呢?

编辑 1: 添加更多信息

XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="@dimen/marintopforelements"
          android:gravity="center"
          android:orientation="vertical"
          android:padding="10dp"
          android:paddingTop="@dimen/templatePaddingTop">

          <android.support.v7.widget.AppCompatEditText
                android:id="@+id/emailresponse"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center"
                android:layout_marginLeft="@dimen/examtextdiff"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:minLines="2"
                android:paddingRight="5dp"
                android:textSize="@dimen/inboxTabTextSize"/>

</LinearLayout>

颜色.xml

<color name="myPrimaryColor">#3F51B5</color>
<color name="myPrimaryDarkColor">#FF304081</color>
<color name="myAccentColor">#3F51B5</color>

所以之前我使用 AppCompat-V7:21 时它像下图一样来了enter image description here

但是升级到AppCompat-V7:22.2.0之后就像下面的图片 enter image description here

所以如果它像下图那样聚焦它的到来 enter image description here

只有该光标线具有给定的强调色。但是提示和文字总是白色的!这甚至发生在两个EditTextAppCompatEditText希望这有帮助

最佳答案

我建议您只为您的 EditText 创建一个主题/样式。 Appcompat默认使用 android:textColorSecondary 作为 EditText 底线的颜色,虽然你没有在你的主题中定义它所以很难说出为什么你的底线行、文本和提示为白色。

这是一个单独的 EditText 主题示例

<style name="ThemeEditTextLight">
    <!-- bottom line color -->
    <item name="colorControlNormal">#000000</item>
    <!-- text color -->
    <item name="android:textColor">#000000</item>
    <!-- hint text color -->
    <item name="android:textColorHint">#BDBDBD</item>
</style>

然后只需将主题设置为您的 EditText:

 <EditText
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="My hint"
     android:theme="@style/ThemeEditTextLight" />

这种方法可以让您更好地控制 EditText 的颜色。

关于android - Edittext 颜色在 appcompat 22.2 中为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31114541/

相关文章:

android - 新的 android 支持设计库,屏幕外滚动 tablayout 不工作

android - 当我在 gradle 中设置的是 appcompat v7 版本 22 时,为什么我的项目总是下载 appcompat v7 版本 23?

android - 更改工具栏后退箭头颜色

java - 应用程序停止使用 appcompat.v7 中的 vector 绘图

android - 以编程方式获取 AAR 版本

android - 在包 'srcCompat' 中找不到属性 'learnapp.android.example.com.learnapp' 的资源标识符

java - 添加按钮时类型不兼容

android - CoordinatorLayout(AppbarLayout) 无法正确绘制工具栏

java - OnClick 后 Activity 关闭

java - 自定义底部导航栏项目布局