Exception when focusing a EditText in a PopupWindow running on Device

后端 未结 7 2057
别那么骄傲
别那么骄傲 2021-02-12 22:38

I\'m developing a PopUp window for Android, and it\'s working, I added a EditText and a Button on that, when running on ADV this work properly, while running on device, when I f

7条回答
  •  我在风中等你
    2021-02-12 23:16

    The crash occurs on an EditText placed in the WindowManager when user taps on a word underlined as red. Such a underlined word means that it does not exist in the dictionary. On the tap, OS tries to show up a pop with closest matching words from the dictionary and crashes since such a pop up can't be attached to the window due to bad token exception.

    Only the following solution seemed to work for me programmatically

    //assume an EditText object with name myEditText
    myEditText.setInputType(myEditText.getInputType() | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    

    InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS does not seem to work as expected on all keyboards whereas InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD has the drawback that it also disables toggling the language in the keyboard and the swipe gesture to add the text.

提交回复
热议问题