Android appcompat 22.2中的Edittext颜色为白色
编辑2:这是因为该行Android appcompat 22.2中的Edittext颜色为白色,android,android-design-library,android-appcompat,Android,Android Design Library,Android Appcompat,编辑2:这是因为该行 @style/ThemeOverlay.AppCompat.Dark.ActionBar 在styles.xml中。我用它来显示浅色(白色)文本和工具栏中的返回主页按钮。如果我将其更改为@style/ThemeOverlay.AppCompat.Light,则EditText按预期工作,但我的工具栏文本和主页按钮颜色将更改为深色(黑色) 由于我使用的是深色的工具栏,我想用浅色(白色)显示文本和返回主页按钮 我尝试使用..而不是..但是没有任何帮助,工具栏文本和后退按钮仍然保
@style/ThemeOverlay.AppCompat.Dark.ActionBar
在styles.xml
中。我用它来显示浅色(白色)文本和工具栏中的返回主页按钮。如果我将其更改为@style/ThemeOverlay.AppCompat.Light
,则EditText
按预期工作,但我的工具栏
文本和主页按钮颜色将更改为深色(黑色)
由于我使用的是深色的工具栏
,我想用浅色(白色)显示文本和返回主页按钮
我尝试使用..
而不是..
但是没有任何帮助,工具栏文本和后退按钮仍然保持深色!有人知道吗?救救我
实际问题:
在一个appcompat-v7:22.2.0
中,我使用了一个EditText
。我正在使用以下主题进行活动
<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>
colors.xml
<color name="myPrimaryColor">#3F51B5</color>
<color name="myPrimaryDarkColor">#FF304081</color>
<color name="myAccentColor">#3F51B5</color>
#3F51B5
#FF304081
#3F51B5
所以之前当我使用AppCompat-V7:21时,就像下图所示
但是升级到AppCompat-V7:22.2.0之后,它就像下图一样
所以,如果它聚焦在下面的图像
只有该光标线具有给定的强调色。但是提示和文本总是白色的!甚至在EditText
和appcompatiedittext
中都会发生这种情况,希望这对您有所帮助我建议您只为您的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>
#000000
#000000
#BDBD
然后只需将主题设置为EditText:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="My hint"
android:theme="@style/ThemeEditTextLight" />
这种方法可以让您更好地控制EditText的颜色。首先,您应该使用EditText,而不是compat。在运行时,仅当需要时,支持库才会将EditText替换为appcompat文本
关于您的问题,appcompat 22.2引入了android:theme而不是app:theme。
我认为您样式中的项目主题没有应用于早期版本的appcompat,现在是
顺便说一下,我不知道在主题中使用主题是否是一种好的做法。好的,我已经解决了强>
我所做的是,我想用白色显示工具栏
内容,因为我的工具栏是黑色的,所以我用了这行
style.xml中的@style/ThemeOverlay.AppCompat.Dark.ActionBar
这在appcompat-v7:21上运行良好
但是在appcompat-v7:22.2.0
中,由于app:theme
被贬低了(由@Guillaume Imbert在他的回答中提到)
这就是困惑。我没有在我的项目中的任何地方使用“app:theme”,但它仍然不断向我发出警告。所以我又一次在谷歌上找到了这个
这让我明白了下面的解释
现在我从style.xml
中删除了@style/ThemeOverlay.AppCompat.Dark.ActionBar
。所以我的工具栏
内容是黑色的(黑色)
最后,在我的工具栏中添加android:theme=“@style/ThemeOverlay.AppCompat.Dark.ActionBar”
成功了,所以我的工具栏代码看起来像
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_size_x2"
android:background="@color/myPrimaryColor"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
所以这可能会帮助一些人
谢谢你给我好的线索,包括反向和纪尧姆·因伯特。没有你的回答,我无法解决这个问题。非常感谢:)请添加更多详细信息:1)您的颜色资源值,例如“myAccentColor”的值是多少?2) EditText所在活动的XML代码。您的意思是EditText、提示和文本的背景色都是白色?这就像将主题应用于单个EditText
。但我的问题是我为什么要这么做!还有别的办法吗?而且colorControlNormal
正在工作。但是android:textColor
和android:textColorHint
不起作用。提示和文本颜色仍然为白色。我更新了我的问题,请再次检查。@KevinChris所以当你使用这种方法时,你的textColor和textColorHint仍然是白色的?是@reVerse。它们仍然是白色的,但背景变为blackHey@reVerse,知道为什么会这样吗?@KevinChris我刚刚创建了一个项目并使用了您的代码-不幸的是,我无法重现您面临的错误。使用完全相同的代码,myEditText
行用蓝绿色,文本颜色为黑色。(默认颜色)。所以最有可能的错误来自其他地方。我不知道我应该在哪里担心android:theme
和app:theme
?我是说在舱单上?如果是这样,在清单中我使用的是android:theme
!如果你能多给我解释一下这件事,我会很有帮助的!更准确地说,使用AppCompat 22,2,您不必担心:app:theme已被弃用。这就是我想说的:现在@style/ThemeOverlay.AppCompat.Dark.ActionBar真的适用了我明白了。在style.xml
中,我使用@style/ThemeOverlay.AppCompat.Dark.ActionBar
以白色显示我的工具栏
文本。这是造成问题的原因。现在,我得到了@style/ThemeOverlay.AppCompat.Light
edittext,正如预期的那样,工作正常,但工具栏文本变为黑色。我使用的是getSupportActionBar().setDisplayHomeAsUpEnabled(true)代码>显示后退按钮。这也变成了黑色。但我希望他们在白色,因为我使用深色的工具栏。我现在该怎么办?正如反面所说的,用s
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_size_x2"
android:background="@color/myPrimaryColor"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>