RuntimeException while using new TextInputLayout from support design library

后端 未结 6 705
情话喂你
情话喂你 2020-12-10 03:37

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



        
相关标签:
6条回答
  • 2020-12-10 03:43

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

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

    to your build.gradle

    0 讨论(0)
  • 2020-12-10 03:43

    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!

    0 讨论(0)
  • 2020-12-10 03:58

    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.

    0 讨论(0)
  • 2020-12-10 04:00

    Make sure app theme extends AppCompat theme.

        <!-- Base application theme. -->
        <style name="AppTheme" parent="@style/Theme.AppCompat">
            <!-- Customize your theme here. -->
        </style>
    
    0 讨论(0)
  • 2020-12-10 04:04

    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

    0 讨论(0)
  • 2020-12-10 04:05

    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.

    0 讨论(0)
提交回复
热议问题