简体   繁体   中英

Android - Error inflating class EditText

Good afternoon, I'm trying to solve a problem but I can not. I have two smartphones, a Nexus 5(Android 6.0) and one ZenFone 2(Android 5.0). The error only persisted only in ZenFone.

XML:

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel">
<EditText
     android:id="@+id/et_login_pass"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:hint="@string/LoginPlaceholderPassword"
     android:inputType="textPassword"/>

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

android.view.InflateException: Binary XML file line #25: Error inflating class EditText at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)

What do I do?

Can you change your layout_width to match_parent and check if your definitely compiling the two dependencies you need in your build.gradle file please.

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

I had the same issue here with ZenFone 2(Android 5.0).

Update your Android Support to:

compile 'com.android.support:design:25.3.0'

Remove:

android:theme="@style/TextLabel"

PS: Please replace fill_parent to match_parent =)

Just create a sub class that extends EditText. For Example:

public class Text extends EditText {
    public Text(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}

Then use this class in xml file instaed of EditText

<com.example.edittextproblem.Text
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="haha"/>

and your problem will be solved :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM