在EditText失去焦点后,SpansionSpan丢失了

时间:2018-08-13 14:29:15

标签: android android-edittext spannablestring spannable spanned

我正在使用SpeechRecognizer获取用户的语音输入并将其显示在EditText内。当SpeechRecognizer返回多个结果时,我将它们显示在SuggestionSpan中。

一切正常,直到EditText失去焦点(点击了另一个EditText)。返回语音识别SuggestionSpans时,所有EditText都会丢失。

我用另一种跨度ForegroundColorSpan进行了测试,当EditText失去焦点时,不会删除该跨度。

用于测试的代码:

SuggestionSpan

            Spannable test = new SpannableString("span test");

            String[] myStringArray = {"foo","boo","cortocala"};
            test.setSpan(new SuggestionSpan(this, myStringArray, FLAG_EASY_CORRECT), 0, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            mContentET.getText().insert(mContentET.length(), test);

ForegroundColorSpan

        Spannable wordtoSpan = new SpannableString("Blue span");
        wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 1, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mContentET.getText().insert(mContentET.length(), wordtoSpan);

SuggestionSpans失去焦点时,移除EditText是正常的吗?从来没有在文档中看到这一点。如果是这样,如何保存?

0 个答案:

没有答案
相关问题