[android] EditText的setError文字不显示问题

  • Post author:
  • Post category:其他


今天写代码,要edittext为空的时候给出提示,用android自带的setError函数,发现文本的颜色和背景的颜色相同,查了一下资料,贴出solution:

在  res/values/styles.xml文件中,在自定义主题里加入一个item:

 <item name="android:textColorPrimaryInverse">@android:color/primary_text_light</item>

完整文件内容如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:textColorPrimaryInverse">@android:color/primary_text_light</item>
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <style name="LoginFormContainer">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:padding">16dp</item>
    </style>
    
    <style name="edittext_style" parent="@android:style/Widget.EditText">
    	<item name="android:background">@drawable/bg_edittext</item>
    	<item name="android:paddingLeft">10dip</item>
    	<item name="android:paddingTop">8dip</item>
    	<item name="android:paddingBottom">8dip</item>
    </style>

</resources>

这样,提示的内容颜色会变为黑色

还不知道怎样改popup的背景颜色,不喜欢默认的白色。

贴上源网址(英文)

https://code.google.com/p/android/issues/detail?id=10378&q=setError&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars



版权声明:本文为yangmingysc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。