InflateException when using TextInputLayout InflateException when using TextInputLayout android android

InflateException when using TextInputLayout


Faced this issue when implementing AndroidX in my existing project.

implementation 'com.google.android.material:material:1.0.0-beta01'

Layout XML

<com.google.android.material.textfield.TextInputLayout    android:id="@+id/userNameWrapper"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:theme="@style/TextLabel">

Old Style

<style name="TextLabel" parent="TextAppearance.AppCompat">        <item name="android:textColorHint">@color/hint_color</item>        <item name="android:textSize">@dimen/text_20sp</item>        <item name="colorControlNormal">@color/primaryGray</item>        <item name="colorControlActivated">@color/colorPrimary</item>    </style>

New Style

<style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">        <item name="android:textColorHint">@color/hint_color</item>        <item name="android:textSize">@dimen/text_20sp</item>        <item name="colorControlNormal">@color/primaryGray</item>        <item name="colorControlActivated">@color/colorPrimary</item>    </style>


Update your themes in @style folder by inheriting one of the followings:

Theme.MaterialComponentsTheme.MaterialComponents.NoActionBarTheme.MaterialComponents.LightTheme.MaterialComponents.Light.NoActionBarTheme.MaterialComponents.Light.DarkActionBar

like this:

    <style name="AppTheme.NoActionBar"    parent="Theme.MaterialComponents.Light.NoActionBar">    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimaryCustom</item>    <item name="colorPrimaryDark">@color/colorPrimaryDarkCustom</item>    <item name="colorAccent">@color/colorAccentCustom</item>    <item name="windowActionBar">false</item>    <item name="windowNoTitle">true</item></style>


It could just be a theme issue. If your TextInputLayout's parent is MaterialComponents (as described below)

<style name="TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">   ...</style>

And if your Activity (or App's) theme derives from AppCompat, your app will crash because MaterialComponents and AppCompat themes are not compatible. For example, the AppTheme (for the activity or the App) CANNOT be as follows:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

You will have to set your AppTheme to MaterialComponents as well, as below:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">   <item name="colorPrimary">@color/colorPrimary</item>   <item name="colorPrimaryDark">@color/colorPrimaryDark</item>   <item name="colorAccent">@color/colorAccent</item></style>

Hopefully, this might work.