在 Android 4.4.2 上创建 TextInputLayout 时膨胀类 Edit

Error inflating class EditText on creating TextInputLayout on Android 4.4.2:(在 Android 4.4.2 上创建 TextInputLayout 时膨胀类 EditText 时出错:)

本文介绍了在 Android 4.4.2 上创建 TextInputLayout 时膨胀类 EditText 时出错:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序的登录页面中使用了 TextInputLayout UI 机制,除了在此设备上运行 4.4.2 android 版本的设备之外,一切都很好.我有一个例外.

I using the TextInputLayout UI mechanism in my login page of the application, everything works great except for device that run the 4.4.2 android version on this devices I have an exception.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<include android:id="@+id/loginInfiLogoRL"
    layout="@layout/login_infi_logo_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="-3dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="10dp"/>

<!--EMAIL-->
<android.support.design.widget.TextInputLayout
    android:id="@+id/email_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/loginInfiLogoRL"
    android:theme="@style/TextLabel">

    <EditText
        android:id="@+id/etUserName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/login_screen_email_hint"
        android:imeOptions="actionNext"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:nextFocusDown="@+id/etPassword"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:textColorHighlight="@color/Orange"
        android:textColorHint="@android:color/white" />

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


<RelativeLayout
    android:id="@+id/rlPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:layout_below="@id/email_wrapper">

    <!--PASSWORD-->
    <android.support.design.widget.TextInputLayout
        android:id="@+id/password_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/TextLabel">

        <EditText
            android:id="@+id/etPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/login_screen_password_hint"
            android:imeOptions="actionNext"
            android:inputType="textPassword"
            android:maxLines="1"
            android:nextFocusDown="@+id/bSignIn"
            android:shadowColor="@color/Orange"
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white" />

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

    <!--FORGOT-->
    <TextView
        android:id="@+id/tvForgotPassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:paddingBottom="14dp"
        android:paddingRight="10dp"
        android:text="@string/login_screen_forgot_password_text"
        android:textColor="@color/Orange"
        android:textSize="16sp" />

</RelativeLayout>

<TextView
    android:id="@+id/tvRememberMe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="invisible" />


<!--Buttons Login and SignUp-->
<LinearLayout
    android:id="@+id/llSignUp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:gravity="center_vertical"
    android:layout_below="@+id/rlPassword">

    <!--Sign up Button-->
    <TextView
        android:id="@+id/bSignUp"
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_marginRight="16dp"
        android:layout_weight="1"
        android:textSize="18sp"
        android:gravity="center"
        android:imeOptions="actionGo"
        android:text="@string/login_screen_sign_up_button_text"
        android:textColor="@color/Orange" />

    <!--Login Button-->
    <Button
        android:id="@+id/bSignIn"
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_marginLeft="16dp"
        android:layout_weight="1"
        android:background="@drawable/fragment_first_use_cloud_get_started_button_background"
        android:focusable="true"
        android:imeOptions="actionGo"
        android:text="@string/login_screen_sign_in_button_text"
        android:textColor="@color/Orange" />

</LinearLayout>

<LinearLayout
    android:id="@+id/llFacebook"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/llSignUp"
    android:gravity="right">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="8dp"
        android:gravity="center"
        android:text="@string/log_in_with_facebook"
        android:textAppearance="@style/TextAppearance.AppCompat.Small.Inverse"
        android:textColor="@android:color/white" />

    <com.facebook.login.widget.LoginButton
        android:id="@+id/bFacebookLogin"
        android:layout_width="@dimen/circular_images_size_l"
        android:layout_height="@dimen/circular_images_size_l"
        android:background="@drawable/btnfbconnect"
        android:text=""
        android:textColor="@android:color/white"/>

</LinearLayout>


<!--Privacy-->
<ImageView
    android:id="@+id/ivLockImage"
    android:layout_width="@dimen/circular_images_size_l"
    android:layout_height="@dimen/circular_images_size_l"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/llFacebook"
    android:layout_marginTop="18dp"
    android:src="@drawable/iconshieldprivacy" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/llSignUp"
    android:layout_alignParentRight="@+id/ivLockImage"
    android:layout_alignRight="@+id/llSignUp"
    android:layout_alignTop="@+id/ivLockImage"
    android:layout_toRightOf="@+id/ivLockImage"
    android:text="@string/login_screen_infi_privacy_title"
    android:textColor="@android:color/white"
    android:textSize="12sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/text1"
    android:layout_width="241dp"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/textView2"
    android:layout_alignRight="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_toRightOf="@+id/ivLockImage"
    android:paddingTop="3dp"
    android:text="@string/login_screen_infi_privacy_description"
    android:textColor="@android:color/white"
    android:textSize="10sp" />

<Space
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="50dp"
    android:layout_alignStart="@+id/text1"
    android:layout_alignLeft="@+id/text1"
    android:layout_below="@+id/text1"
    android:layout_alignParentBottom="true" />
</RelativeLayout>

更新:这是xml样式:

    <style name="TextLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">@android:color/white</item>
    <item name="android:textColorHighlight">@android:color/white</item>
    <item name="android:textColorLink">@android:color/white</item>
    <item name="android:textSize">20sp</item>
    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@color/accent</item>
    <item name="colorControlNormal">@android:color/white</item>
    <item name="colorControlActivated">@color/accent</item>
</style>

这是个例外:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infibond.infi/com.infibond.account.login.LoginActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class EditText
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2281)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
   at android.app.ActivityThread.access$800(ActivityThread.java:139)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5230)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
   at dalvik.system.NativeStart.main(NativeStart.java)
Caused by android.view.InflateException: Binary XML file line #22: Error inflating class EditText
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:92)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
       at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
       at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
       at android.app.Activity.performStart(Activity.java:5421)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2242)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
       at android.app.ActivityThread.access$800(ActivityThread.java:139)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5230)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
       at android.content.res.TypedArray.getColor(TypedArray.java:327)
       at android.widget.TextView.<init>(TextView.java:703)
       at android.widget.EditText.<init>(EditText.java:61)
       at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
       at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56)
       at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
       at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
       at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:92)
       at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
       at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
       at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
       at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
       at android.app.Activity.performStart(Activity.java:5421)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2242)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
       at android.app.ActivityThread.access$800(ActivityThread.java:139)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5230)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
       at dalvik.system.NativeStart.main(NativeStart.java)

为什么会发生这种情况,修复它的正确方法是什么?

Why does this happen, and what is the proper way to fix it?

推荐答案

解决此问题的方法是从样式配置中删除 parent="TextAppearance.AppCompat":

What fixed this issue was removing the parent="TextAppearance.AppCompat" from the style configuration:

所以现在样式如下:

<style name="TextLabel">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">@color/White</item>
    <item name="android:textColorHighlight">@android:color/white</item>
    <item name="android:textColorLink">@color/White</item>
    <item name="android:textSize">20sp</item>
    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@color/accent</item>
    <item name="colorControlNormal">@android:color/white</item>
    <item name="colorControlActivated">@color/accent</item>
</style>

在xml布局中:

<android.support.design.widget.TextInputLayout
    android:id="@+id/email_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/loginInfiLogoRL"
    android:theme="@style/TextLabel">

    <EditText
        android:id="@+id/etUserName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/login_screen_email_hint"
        android:imeOptions="actionNext"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:nextFocusDown="@+id/etPassword"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:textColorHighlight="@color/White"
        android:textColorHint="@android:color/white" />

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

这篇关于在 Android 4.4.2 上创建 TextInputLayout 时膨胀类 EditText 时出错:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Android 4.4.2 上创建 TextInputLayout 时膨胀类 Edit

基础教程推荐