Android N crashes in TextAppearanceSpan

前端 未结 3 475
说谎
说谎 2020-12-30 06:33

Since upgrading my Nexus 5X to Android N, I have the following crash when using EditText:

   java.lang.UnsupportedOperationException: Failed to resolve attri         


        
相关标签:
3条回答
  • 2020-12-30 07:17

    Add this to your Edit text view android:textAppearance="@color/" like this:

    <EditText 
          android:textAppearance="@color/abc_primary_text_disable_only_material_dark"
          ...
    />
    

    "@color/abc_primary_text_disable_only_material_dark" (built in) :

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="false" android:color="@color/bright_foreground_disabled_material_dark"/>
        <item android:color="@color/bright_foreground_material_dark"/>
    </selector>
    

    it works for me

    0 讨论(0)
  • 2020-12-30 07:26

    In the stack trace there was a reference to SuggestionsPopupWindow that made me think of disabling suggestions for EditText.

    I used the following code as a workaround:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            if ((editText.getInputType() & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) {
                editText.setInputType(editText.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
            }
        }
    

    We can also set inputType in XML, but the above code allows us to add TYPE_TEXT_FLAG_NO_SUGGESTIONS to existent input type.

    0 讨论(0)
  • 2020-12-30 07:39

    Updating the support library to 25.0.0 or higher fixes this issue

    0 讨论(0)
提交回复
热议问题