Android N crashes in TextAppearanceSpan

前端 未结 3 474
说谎
说谎 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: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.

提交回复
热议问题