Better way to get all the text in an EditText from an InputConnection?

后端 未结 2 888
日久生厌
日久生厌 2021-02-04 12:34

I\'ve written an IME (InputMethodService) and I need to get all the text from the EditText it is editing. I know one way:

InputConnection inputConnection = getCu         


        
相关标签:
2条回答
  • 2021-02-04 12:57

    My solution is to use getExtractedText(). I am not sure if this has some limitations, but has worked for me so far.

    CharSequence currentText = inputConnection.getExtractedText(new ExtractedTextRequest(), 0).text;
    
    0 讨论(0)
  • 2021-02-04 12:58

    Here is also another way to do it:

    inputConnection.performContextMenuAction(android.R.id.selectAll);
    CharSequence sData =  inputConnection.getSelectedText(0);
    
    0 讨论(0)
提交回复
热议问题