• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Adding a TextInputLayout

Greum

Well-Known Member
I'm trying to add a floating label to one of my EditTexts .

I have added the dependency

implementation 'com.android.support:design:28.0.0'

And then I wrapped the EditText with a TextInputLayout and changed the EditText to TextInputEditText

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

        <android.support.design.widget.TextInputEditText
            android:id="@+id/editName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/text_name"
            android:inputType="textPersonName" />

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

But when I run that layout the app crashes.

The first few lines of the error log are:

Code:
2019-07-25 19:40:45.717 7492-7492/com.domain.agedatabase E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.domain.agedatabase, PID: 7492
    android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.support.design.widget.TextInputLayout
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.design.widget.TextInputLayout
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout" on path: DexPathList[[zip file "/data/app/com.domain.agedatabase-XIahRtMJot7YD30IBJ79pQ==/base.apk", zip file "/data/app/com.domain.agedatabase-XIahRtMJot7YD30IBJ79pQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.domain.agedatabase-XIahRtMJot7YD30IBJ79pQ==/split_lib_resources_apk.apk", zip file
 
Do you have this dependency in your build.gradle?

compile 'com.android.support:design:25.3.1'
 
Do you have this dependency in your build.gradle?

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

Yes, I added that but I get an error saying to use version 28 (compileSdkVersion), so I changed it to 28.0.0. Then I get a warning saying compile is obsolete and should be replaced with implementation, so I ended up with

implementation 'com.android.support:design:28.0.0'
 
I'm thinking maybe I should be using the androidx equivalent, but finding out what that should be is another matter...
 
Okay, so I created a simple app in android then refactored it to androidx.

The tags seem to be changed

<com.google.android.material.textfield.TextInputLayout

and

<com.google.android.material.textfield.TextInputEditText

and it doesn't need the extra dependency, so long as there's

implementation 'com.google.android.material:material:1.0.0'
 
Back
Top Bottom