14

I have very simple layout where I use new android.support.design.widget.TextInputLayout view from Design Support Library

<android.support.design.widget.TextInputLayout
    android:id="@+id/til"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <EditText
        android:id="@+id/textDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="First Name"/>
</android.support.design.widget.TextInputLayout>

On inflate I get exception:

Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 18
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166)
            at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)
            at android.app.Activity.setContentView(Activity.java:2144)
            at com.example.trybindinglib.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2407)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:211)
            at android.app.ActivityThread.main(ActivityThread.java:5321)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Oleksii Masnyi
  • 2,922
  • 2
  • 22
  • 27
  • Wasn't 'fill_parent' deprecated 5 years ago? That should generate one more warning – milosmns May 31 '15 at 22:03
  • did you find a fix for this problem? Im getting the same error. if you have found a problem, can you please post it as an answer :) – edwinj Oct 22 '15 at 17:08
  • Similar issue: http://stackoverflow.com/questions/35767158/android-edittext-with-textinputlayout-crashing-when-reaching-limit-of-countermax – Jonas May 18 '16 at 13:02

6 Answers6

15

Have you added the Design Support Library? Add the dependency:

compile 'com.android.support:design:22.2.0'

to your build.gradle

Luchi Valles
  • 181
  • 4
9

If you are using Theme.AppCompat as your Base application theme, define the textColorError in it. TextInputLayout needs it to use in it's error states. Else will show the crash log just as mentioned above.

Example:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="textColorError"> @color/design_textinput_error_color_light </item>
</style>

It is @color/design_textinput_error_color_light for AppCompat.Light and @color/design_textinput_error_color_dark for AppCompat.Dark.

Asha Antony
  • 441
  • 5
  • 8
6

Make sure app theme extends AppCompat theme.

    <!-- Base application theme. -->
    <style name="AppTheme" parent="@style/Theme.AppCompat">
        <!-- Customize your theme here. -->
    </style>
Oleksii Masnyi
  • 2,922
  • 2
  • 22
  • 27
4

I had the same problem on a raw application generated with Android Studio.

I solved it by first adding the following dependency to my build.gradle compile 'com.android.support:appcompat-v7:22.2.0'

Then I had to modify the theme base to @style/Theme.AppCompat as suggested by Aleksey. Notice here that you will probably have to rename your base theme as there is one with the same name (AppTheme) in appcompat library, and AS seems to get messed between the two...

Hope this helps!

malrok44
  • 592
  • 6
  • 17
1

getColor crashes, you can try two things:

1.Instead of using EditText, use android.support.v7.widget.AppCompatEditText. For example:

<android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:errorEnabled="true">
                <android.support.v7.widget.AppCompatEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="First Name"
                    android:inputType="textPersonName"
                    android:singleLine="true" />

</android.support.design.widget.TextInputLayout>

2.If that doesn't help, this might, but it will remove the color of your hint when the input field is selected. Add:

            app:hintTextAppearance="@android:style/TextAppearance.Small"

to your TextInputLayout.

Frank
  • 12,010
  • 8
  • 61
  • 78
  • After trying everything else, switching the EditText to an AppCompatEditText fixed my issue. Thanks!! – FinHead Apr 15 '16 at 13:53
1

Make sure your XML looks like:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="search" />
</android.support.design.widget.TextInputLayout>

full example:

http://hmkcode.com/android-textinputlayout/

No themeStyle change needed

itzhar
  • 12,743
  • 6
  • 56
  • 63