Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextInputField Inflator Error

Had a crash while trying to use the new TextInputField for Android and wanted to share my solution.

Trying the new TextInputField in the android appcompat library was crashing my app. Here was my layout xml.

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

    <EditText
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="e-mail"
        android:inputType="textEmailAddress"
        android:singleLine="true"/>

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

The error I got:

android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.TextInputLayout.

SOLUTION: Add the hintTextAppearance attribute to your TextInputLayout, so the lead tag looks like this:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintTextAppearance="@android:style/TextAppearance.Medium">
like image 879
eimmer Avatar asked Jun 01 '15 16:06

eimmer


3 Answers

Make sure you have the following dependencies in your gradle file:

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'

Working example:

<android.support.design.widget.TextInputLayout
    android:id="@+id/txtEmail_InpLyt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/txtEmail"
        android:hint="Email Address"
        android:singleLine="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>
</android.support.design.widget.TextInputLayout>

(Setting hintTextAppearance is not necessary.)

Update:

If you experience issues with the hint text not appearing in newer versions of Android (Marshmallow / Nougat), update library to version 22.2.1 (see TextInputLayout not showing EditText hint before user focus on it).

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
like image 198
Rachel Avatar answered Nov 11 '22 13:11

Rachel


This happened to me as well, and I came up with a solution that does not require changing the App Theme, but merely changing the Theme of the TextInputLayout:

<android.support.design.widget.TextInputLayout
    android:id="@+id/testingInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Theme.AppCompat">

   <EditText
       android:id="@+id/testingEditText"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:hint="@string/testText"
       android:inputType="textEmailAddress" />

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

You will need to add the appCompat library if you have not already:

compile 'com.android.support:appcompat-v7:23.0.1'
like image 24
Phil Avatar answered Nov 11 '22 14:11

Phil


in adroidx it worked for me i have the libraries

 implementation 'com.android.support:appcompat-v7:28.0.0'
    //design widget
    implementation 'com.android.support:design:28.0.0'

i change

<android.support.design.widget.TextInputLayout

for

<com.google.android.material.textfield.TextInputLayout
like image 19
Jhon Jesus Avatar answered Nov 11 '22 14:11

Jhon Jesus