InflateException with TextInputLayout and AlertDialog

前端 未结 7 592
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 05:55

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

Here\'s my code:



        
相关标签:
7条回答
  • 2020-12-11 06:20

    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.

    0 讨论(0)
  • 2020-12-11 06:24

    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">
    
    0 讨论(0)
  • 2020-12-11 06:24

    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.

    0 讨论(0)
  • 2020-12-11 06:30

    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);
    
    0 讨论(0)
  • 2020-12-11 06:35

    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.

    0 讨论(0)
  • 2020-12-11 06:46

    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'
    
    0 讨论(0)
提交回复
热议问题