Skip to content Skip to sidebar Skip to footer

Inflateexception With Textinputlayout And Alertdialog

I am trying to use the newest TextInputLayout in my DialogFragment. Here's my code:

Solution 1:

This happened to me as well, and I came up with a solution inspired by AHTOH's. It requires simply 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'

Solution 2:

I had similar error:

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

Trying to reproduce it for a new project I found that the problem for me was in App Theme! Try to set android:theme field in application tag of Android Manifest like this:

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat">

Solution 3:

  • extend your activity from AppCompatActivity
  • extend your (dialog)fragment from android.support.v4.app.Fragment.
  • use latest version of design library.
  • Instead of using EditText, use android.support.v7.widget.AppCompatEditText. For example:

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

Also, if you didn't do so already: Set AppCompat theme in your manifest application tag:

<application...android:theme="@style/Theme.AppCompat">

And inherit AppCompat at your styles.xml as root for your activity styles etc.:

<stylename="AppTheme"parent="Theme.AppCompat.Light.NoActionBar"/>

Solution 4:

Even though the Theme is set properly in the manifest, this might happen depending on the Context you are inflating from. You can fix this by using a ContextWrapper with your AppTheme (or another one) when initialising the LayouInflater:

LayoutInflaterinflater= LayoutInflater.from(newContextThemeWrapper(getApplicationContext(), R.style.AppTheme));
Viewview= inflater.inflate(R.layout.your_dialog_layout, null);

Solution 5:

With recent announcement in Google I/O 2018, and refractor of com.android. to androidx. all support libraries got affected too.

So, you may have to change your dependencies to com.google.android.material:material:<Major.Version.Number><-beta|alpha Version> as of 06th of July 2018, I am using com.google.android.material:material:1.0.0-beta01

And above the class <android.support.design.widget.TextInputLayout and <android.support.design.widget.TextInputEditText has been changed to com.google.android.material.textfield.TextInputLayout and com.google.android.material.textfield.TextInputEditText

Have a look at this link to get a better idea of what all support libraries got refractored.

Good luck.

Post a Comment for "Inflateexception With Textinputlayout And Alertdialog"