引起:java.lang.UnsupportedOperationException:无法解析索引4处的属性:TypedValue {t = 0x2 / d = 0x1010099 a = 1}

时间:2018-06-15 12:19:27

标签: android android-edittext android-textinputlayout

我在Android设备SM-J727U上遇到以下异常但在其他设备上没有崩溃。我读了一些堆栈溢出答案,它只影响了Android 7.0上的一些新的Android设备。

任何人都可以建议如何解决它以及导致它发生的原因。

由于 [R

这是个例外。

    Terminating app due to an uncaught exception 'java.lang.UnsupportedOperationException', reason: 'Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1}' 
Last Exception Backtrace
0   android.view.InflateException: Binary XML file line #43: Binary XML file line #43: Error inflating class TextView
1   Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class TextView
2   Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1}
3   at android.content.res.TypedArray.getColor(TypedArray.java:476)
4   at android.widget.TextView.<init>(TextView.java:1105)
5   at android.widget.TextView.<init>(TextView.java:1018)
6   at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:76)
7   at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:72)
8   at android.support.v7.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:176)
9   at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
10  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)
11  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)

XML

<android.support.design.widget.TextInputLayout
                android:id="@+id/til_user_full_names"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:theme="@style/EmployeeFieldLabel"
                android:layout_below="@+id/tv_english_characters_only">           

     <EditText
                    android:id="@+id/user_full_names"
                    android:layout_width="match_parent"
                    style="@style/EmployeeFieldTextStyle"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="@string/names_as_it_appears_on_id"
                    android:inputType="textPersonName"/>

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

样式

<style name="EmployeeFieldLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">#9e9e9e</item>
    <item name="android:textSize">@dimen/dp_text_size_medium</item>

    <item name="colorControlActivated">@color/blueyPurple</item>
</style>

<style name="EmployeeFieldTextStyle">
    <item name="android:textSize">@dimen/dp_text_size_medium</item>
    <item name="android:textColor">#000000</item>
    <item name="android:textCursorDrawable">@null</item>
    <item name="fontPath">fonts/OpenSans-Regular.ttf</item>
    <item name="android:background">@drawable/bg_field</item>
</style>

1 个答案:

答案 0 :(得分:0)

原因是谷歌拼写检查弹出窗口,在某些设备中启用,导致Edittext中的单词下面出现红线

使用此

在您的样式中

<item name="colorControlHighlight"></item>

在您的xml

 android:inputType="textNoSuggestions"

而不是

 android:inputType="textPersonName"


 <item name="colorControlActivated">@color/blueyPurple</item>