I have a text input layout, and I want to use it to display an error message if the data entered into the editable text inside it is incorrect. The definitions are as follows:
<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>
The style is defined as follows:
<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>
Now, if the entered data is incorrect, I perform the following operations:
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();
When all this is done, I get an error message:
Can't convert to color: type=0x2 in the string numberInputLayout.setErrorEnabled(true);
Where am I going wrong?
EDIT 1: As soon as I delete the TextLabelWhite theme, it starts to work. But the topic is necessary.
android android-edittext
Prakhar Mohan Srivastava Jan 18 '16 at 11:40 2016-01-18 11:40
source share