在Appcompat 22.2中Edittext颜色为白色 [英] Edittext color is white in appcompat 22.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
中存在错误,但是如何解决此问题?
添加更多信息
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>
colors.xml
<color name="myPrimaryColor">#3F51B5</color>
<color name="myPrimaryDarkColor">#FF304081</color>
<color name="myAccentColor">#3F51B5</color>
所以以前我在使用AppCompat-V7:21
时,它就像下面的图像一样 >
但是升级到AppCompat-V7:22.2.0
后,如下图所示
因此,如果它像下面的图像一样聚焦它的到来
仅该光标线具有给定的强调色.但是提示和文本始终为白色!甚至在EditText
和AppCompatEditText
中都在发生这种情况,希望对您有所帮助
好的,我已解决问题!
我正在做的是,我想以白色显示ToolBar
内容,因为我的工具栏很暗,所以我使用了这行
styles.xml
中的 <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
在appcompat-v7:21.+
上运行正常.
但是在appcompat-v7:22.2.0
中,由于app:theme
被贬值(@Guillaume Imbert在他的回答中提到).
这就是混乱.我在项目中的任何地方都没有使用过"app:theme",但它仍然向我显示警告.因此,我再次谷歌搜索并找到了此链接.
哪些人引导我关注Chris的博客Banes 对此进行了清晰的解释.
现在我从styles.xml
中删除了<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
.所以我的ToolBar
内容是暗的(黑色).
最后在ToolBar
中添加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"/>
因此,这可能会对某人有所帮助.
感谢@reVerse和@Guillaume Imbert给我带来好的领导.没有您的回答,我将无法解决.非常感谢:)
EDIT 2 : This is happening because of the line
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
in styles.xml
. I'm using this to display light color (white) texts and back home button in ToolBar
. If i change this to <item name="theme">@style/ThemeOverlay.AppCompat.Light</item>
then EditText
is working as expected but my ToolBar
text and back home button colors are changes to dark (black).
As I'm using dark colored ToolBar
I would like to show the text and back home button in light (white) color.
I tried using <item name="android:theme">...</item>
instead of <item name="theme">...</item>
But nothing helped me, The toolbar text and back button still remains dark color! Any one figured out? Help me!
ACTUAL QUESTION :
In an appcompat-v7:22.2.0
I used an EditText
. An I'm using following theme for an 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>
But the color of an EditText
is coming in white color. Bottom line, hint and text all are in white. I heard there is a bug in AppCompat
But how to resolve this?
EDIT 1 : Adding more information
XML file :
<?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>
colors.xml
<color name="myPrimaryColor">#3F51B5</color>
<color name="myPrimaryDarkColor">#FF304081</color>
<color name="myAccentColor">#3F51B5</color>
So previously when I was using AppCompat-V7:21
It was coming like below image
But after upgrading to AppCompat-V7:22.2.0
Its like below image
So if it focused its coming like below image
Only that cursor line is in given accent color. But the hint and text are always in white! And this is happening even in both EditText
and AppCompatEditText
Hope this helps
Okie, I fixed it!
What I was doing was, I want to display ToolBar
content in white color as my ToolBar is dark so I used this line
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
in styles.xml
This was working fine with appcompat-v7:21.+
.
But in appcompat-v7:22.2.0
as the app:theme
was depreciated (mentioned by @Guillaume Imbert in his answer).
So here was the confusion. I didn't use 'app:theme` any where in my project but it still keep showing me warning. So again I googled and found the this link.
Which leads me to following blog by Chris Banes clearly explained about it.
Now I removed <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
from styles.xml
. So my ToolBar
content is dark (Black).
Finally adding android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
in my ToolBar
did the trick, So my toolbar code looks like
<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"/>
So this may help someone.
Thanks for giving me the good lead, both @reVerse and @Guillaume Imbert. Without your answers I would not able to fix this. Thanks a Lot :)
这篇关于在Appcompat 22.2中Edittext颜色为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!