Reputation: 1696
I have designed a customised InputTextLayout which contains a custom Edittext.This custom Edittext extends the "AppCompatEdittext". Also my MainActivity extends AppCompatActivity. But still I am not able to show the error messages using TextInputLayout. Below are my code snippets from various files.
main.xml
<android.support.design.widget.TextInputLayout
android:id="@+id/last_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/first_name_layout"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="12dp"
android:background="@drawable/grey_button_normal"
android:hint="Last name"
android:minHeight="48dp"
android:paddingTop="3dp"
android:theme="@style/TextLabel">
<com.feebite.widgets.StyleableEditText
android:id="@+id/lastname_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:gravity="center_vertical"
android:minHeight="48dp"
android:nextFocusDown="@+id/email_edittext"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:singleLine="true"
android:textColor="@color/darkish_grey"
android:textColorHint="@color/darkish_grey"
android:textCursorDrawable="@null"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
MainActivity.java
mLastNameLayout = (TextInputLayout) findViewById(R.id.last_name_layout);
mLastNameLayout.setHint("Last name");
mLastNameLayout.setErrorEnabled(true);
Custom theme from styles.xml
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@color/darkish_grey</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/darkish_grey</item>
<item name="colorControlNormal">@color/darkish_grey</item>
<item name="colorControlActivated">@color/dark_pink</item>
</style>
And the error displayed.
FATAL EXCEPTION: main
Process: com.feebite, PID: 18611
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.feebite/com.feebite.userRegisteration.SignUpActivity}: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x45a "res/color/secondary_text_material_light.xml" a=1 r=0x106011e}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x45a "res/color/secondary_text_material_light.xml" a=1 r=0x106011e}
at android.content.res.TypedArray.getColor(TypedArray.java:447)
at android.content.res.XResources$XTypedArray.getColor(XResources.java:1033)
at android.widget.TextView.<init>(TextView.java:738)
at android.widget.TextView.<init>(TextView.java:671)
at android.widget.TextView.<init>(TextView.java:667)
at android.widget.TextView.<init>(TextView.java:663)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
at com.feebite.userRegisteration.SignUpActivity.onCreate(SignUpActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
Upvotes: 10
Views: 3252
Reputation: 16359
There are different attributes you could be using for your TextInputLayout, as
app:errorEnabled
: To toggle error visibility and use an empty string when no error should be shown. We could also use setError(null).
app:errorTextAppearance
: Text appearance for the error text. We could use something like @style/TextInputLayout.ErrorText.
app:hintTextAppearance
: Text appearance for the hint text. We could use something like @style/TextInputLayout.HintText.
where:
<style name="TextInputLayout"/>
<style name="TextInputLayout.ErrorText">
<item name="textColorError">#FFD50000</item>
</style>
<style name="TextInputLayout.HintText">
<item name="android:textColor">?attr/colorPrimary</item>
<item name="android:textSize">@dimen/text_tiny_size</item>
</style>
The one you are looking for is app:errorTextAppearance
. You could also use android:theme
to make the container's small EditText (hint) inherit your application theme configuration.
Upvotes: 0
Reputation: 11901
Had exactly the same problem and none of the answers solved.
What really worked was removing this: parent="TextAppearance.AppCompat"
Upvotes: 5
Reputation: 339
Try to set the following attributes too:
<item name="android:textColorHighlight">@color/Your color</item>
<item name="android:textColorLink">@color/Your color</item>
Upvotes: 33