Android文字输入布局

我有一个文本输入布局,如果在其中的编辑文本中输入的数据不正确,我想使用它来显示错误消息.定义如下:
<android.support.design.widget.TextInputLayout
            android:id="@+id/number_input_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/TextLabelWhite" >

            <EditText
                android:id="@+id/number_edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:digits="01234 56789"
                android:hint="Number"
                android:inputType="number"
                android:textColor="@color/white" />
</android.support.design.widget.TextInputLayout>

样式定义如下:

<style name="TextLabelWhite" parent="TextAppearance.AppCompat">
    <item name="android:textColorHint">@color/white</item>
    <item name="colorAccent">@color/white</item>
    <item name="colorControlnormal">@color/white</item>
    <item name="colorControlActivated">@color/white</item>
</style>

现在,如果输入的数据不正确,我会执行以下操作:

TextInputLayout numberInputLayout = (TextInputLayout) view.findViewById(R.id.number_input_layout);
EditText numberEditText = (EditText) getView().findViewById(R.id.number_edit_text);
numberEditText.getBackground().setColorFilter(Color.RED,PorterDuff.Mode.SRC_ATOP);
numberInputLayout.setErrorEnabled(true);
numberEditText.setError("Tis an error dear");
Toast.makeText(getActivity(),error,Toast.LENGTH_SHORT).show();

完成所有这些后,我得到错误

无法转换为color:type = 0x2,行numberInputLayout.setErrorEnabled(true);

我哪里错了?

编辑1:一旦我删除TextLabelWhite主题,它就开始工作.但这个主题是必要的.

解决方法

更改
android:theme="@style/TextLabelWhite"

style="@style/TextLabelWhite"

在xml中的android.support.design.widget.TextInputLayout属性中,您将不会收到错误.

更新:要自定义颜色,您可以尝试这个.加

<item name="colorControlnormal">@android:color/white</item>
<item name="colorControlActivated">@android:color/white</item>

直接到您的应用主题样式.它会影响所有EditText,但如果它对您的应用程序不是问题,它可能会有所帮助.

更新2:

我找到的最好的解决方案.使用

android:theme="@style/TextLabelWhite"

就像你的xml一样.将TextLabelWhite样式父级更改为AppTheme样式,如:

<style name="TextLabelWhite" parent="AppTheme">

但android:textColorHint不适用于TextInputLayout(没有这样的属性).您应该使用design:hintTextAppearance,但将其置于不同的样式并直接应用于TextInputLayout

design:hintTextAppearance="@style/CustomTextAppearance"

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...