7

I am trying to use the newest TextInputLayout in my DialogFragment.

Here's my code:

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

   <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>

Some background info:

  • The activity that launches the DialogFragment derives from AppCompatActivity
  • The DialogFragment derives from Android.Support.V4.App.DialogFragment
  • I build the DialogFragment via the Android.Support.V7.App.AlertDialog.Builder
  • The DialogFragment is launched via a SupportFragmentManager
  • I am using the latest Support Design Library

Here's the error (I'm using Xamarin, hence the MonoDroid)

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
[MonoDroid] at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue*) [0x00064] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195
[MonoDroid] at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x0006d] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.LayoutInflater.cs:646
[MonoDroid] at HelloLittleApp.MyOwnDialog.OnCreateDialog (Android.OS.Bundle) [0x00027] in e:\Progetti\HelloLittleApp-Android\Dialogs\MyOwnDialog.cs:22
[MonoDroid] at Android.Support.V4.App.DialogFragment.n_OnCreateDialog_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00013, 0x000f7>
[MonoDroid] at (wrapper dynamic-method) object.e260d9fd-b921-4418-a47a-496934404e0e (intptr,intptr,intptr) <IL 0x00017, 0x0004b>
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout
[MonoDroid]     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
[MonoDroid]     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
[MonoDroid]     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
[MonoDroid]     at md5a2b8d0e6e3890b714223a2b1204f749c.MyOwnDialog.n_onCreateDialog(Native Method)
[MonoDroid]     at md5a2b8d0e6e3890b714223a2b1204f749c.MyOwnDialog.onCreateDialog(MyOwnDialog.java:29)
[MonoDroid]     at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:308)
[MonoDroid]     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
[MonoDroid]     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
[MonoDroid]     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
[MonoDroid]     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
[MonoDroid]     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
[MonoDroid]     at android.os.Handler.handleCallback(Handler.java:739)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid]     at android.os.Looper.loop(Looper.java:135)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5254)
[MonoDroid]     at java.lang.reflect.Method.invoke(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:372)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
[MonoDroid] Caused by: java.lang.reflect.InvocationTargetException
[MonoDroid]     at java.lang.reflect.Constructor.newInstance(Native Method)
[MonoDroid]     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
[MonoDroid]     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
[MonoDroid]     ... 21 more
[MonoDroid] Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 18
[MonoDroid]     at android.content.res.TypedArray.getColor(TypedArray.java:401)
[MonoDroid]     at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166)
[MonoDroid]     at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106)
[MonoDroid]     ... 24 more
[AndroidRuntime] Shutting down VM

Any tip is appreciated.

Bacco
  • 143
  • 1
  • 1
  • 5

7 Answers7

18

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'
Community
  • 1
  • 1
Phil
  • 35,852
  • 23
  • 123
  • 164
14

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">
AHTOH
  • 446
  • 4
  • 16
  • It worked for me too, but it also removed my ActionBar! – prograde Jul 24 '15 at 22:34
  • 3
    Oops, you also need to implement AppCompatActivity instead of Activity. Then it works fine. – prograde Jul 25 '15 at 17:30
  • 1
    My minimumSDK and targetSDK are API 22. Should I use `@style/Theme.AppCompat` or `@style/android:Theme.Material` ? – Solace Aug 22 '15 at 08:53
  • My style is `Theme.AppCompat.Light.NoActionBar` however in `values-c21` styles file i found resource tag started like this `>` instead of `` could that be the reason for this error `Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/design_password_eye.xml from drawable resource ID ` – Edijae Crusar Mar 09 '17 at 13:31
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.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>
    

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.:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
Frank
  • 12,010
  • 8
  • 61
  • 78
3

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.

Shreyansh Lodha
  • 83
  • 2
  • 10
3

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:

LayoutInflater inflater = LayoutInflater.from(new ContextThemeWrapper(getApplicationContext(), R.style.AppTheme));
View view = inflater.inflate(R.layout.your_dialog_layout, null);
goemic
  • 1,092
  • 12
  • 24
1

i had the android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout error too. It turned out to be caused by my proguard/gradle config . I was using the shrinkResources directive in my release build config.

After i removed the shrinkResources directive from my release build config everything started working again.

Hope it helps someone.

Williem
  • 1,131
  • 1
  • 12
  • 19
0

I experienced this error but it ended up being a completely different context. I didn't see my exact issue outlined elsewhere so posting an answer here hoping it will save others time. In my case, this exception was thrown:

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

However, it was related to the implementation for the FileProvider camera permissions. That implementation involved adding an xml file under Resources/xml.

Having anything in the Resources/xml folder would throw the exception. Both FileProvider and TextInputLayout worked independently but not when used in the same project.

The result that worked for me was to move all xml files from Resource/xml to Resources/layout and reference them with @layout/my_reference_here.

This seems like a bug in Visual Studio/Xamarin, but at least I was able to move forward. I hope this helps another avoid burning a couple of days of time hunting it down.

ctc
  • 3,373
  • 1
  • 18
  • 14