仅在两款ASUS智能手机(Asus Zenfone 5 - API 19和Asus Zenfone 2 - API 21)上膨胀EditText时才会抛出此异常。其他设备/模拟器均正常工作。
完整堆栈跟踪:
Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.example/com.package.example.activity.SignUpActivity}: android.view.InflateException: Binary XML file line #47: Error inflating class EditText
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2318)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2396)
android.app.ActivityThread.access$800 (ActivityThread.java:139)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1293)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:149)
android.app.ActivityThread.main (ActivityThread.java:5257)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:609)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #47: Error inflating class EditText
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:713)
android.view.LayoutInflater.rInflate (LayoutInflater.java:755)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:839)
android.view.LayoutInflater.rInflate (LayoutInflater.java:745)
android.view.LayoutInflater.inflate (LayoutInflater.java:492)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate (CalligraphyLayoutInflater.java:60)
android.view.LayoutInflater.inflate (LayoutInflater.java:397)
android.view.LayoutInflater.inflate (LayoutInflater.java:353)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:284)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:143)
com.package.example.activity.SignUpActivity.onCreate (SignUpActivity.java:88)
android.app.Activity.performCreate (Activity.java:5411)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1087)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2270)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2396)
android.app.ActivityThread.access$800 (ActivityThread.java:139)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1293)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:149)
android.app.ActivityThread.main (ActivityThread.java:5257)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:609)
dalvik.system.NativeStart.main (NativeStart.java)
arrow_drop_down
Caused by java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
android.content.res.TypedArray.getColor (TypedArray.java:327)
android.widget.TextView.<init> (TextView.java:700)
android.widget.EditText.<init> (EditText.java:61)
android.support.v7.widget.AppCompatEditText.<init> (AppCompatEditText.java:62)
android.support.v7.widget.AppCompatEditText.<init> (AppCompatEditText.java:58)
android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:112)
android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1017)
android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1076)
android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView (LayoutInflaterCompatHC.java:44)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView (CalligraphyLayoutInflater.java:280)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:684)
android.view.LayoutInflater.rInflate (LayoutInflater.java:755)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.rInflate (LayoutInflater.java:758)
android.view.LayoutInflater.parseInclude (LayoutInflater.java:839)
android.view.LayoutInflater.rInflate (LayoutInflater.java:745)
android.view.LayoutInflater.inflate (LayoutInflater.java:492)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate (CalligraphyLayoutInflater.java:60)
android.view.LayoutInflater.inflate (LayoutInflater.java:397)
android.view.LayoutInflater.inflate (LayoutInflater.java:353)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:284)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:143)
com.package.example.activity.SignUpActivity.onCreate (SignUpActivity.java:88)
android.app.Activity.performCreate (Activity.java:5411)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1087)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2270)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2396)
android.app.ActivityThread.access$800 (ActivityThread.java:139)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1293)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:149)
android.app.ActivityThread.main (ActivityThread.java:5257)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:609)
dalvik.system.NativeStart.main (NativeStart.java)
布局
<android.support.design.widget.TextInputLayout
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
app:errorTextAppearance="@style/AppTheme.Error"
app:hintEnabled="true"
app:theme="@style/AppTheme.TextInput.White">
<android.support.design.widget.TextInputEditText
android:id="@+id/nickname"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_username"
android:inputType="textPersonName"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
Theme
<style name="AppTheme.TextInput.White" parent="TextAppearance.AppCompat">
<item name="colorControlNormal">@color/whiteC</item>
<item name="colorControlActivated">@color/white</item>
<item name="android:textColorHighlight">@color/whiteC</item>
<item name="android:textColorLink">@color/whiteC</item>
<item name="android:textColorHint">@color/whiteC</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--Error-->
<style name="AppTheme.Error" parent="AppTheme.Text.White">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">italic</item>
</style>
我已经尝试过的方法:
- 将TextInputEditText替换为EditText
- 从EditText中删除textColor="@color/white"
- 降级到支持库24、23。(当前我使用的是25.0.1)