How to get selected text from edittext in android?

前端 未结 2 1078
情深已故
情深已故 2021-02-07 20:50

I have a edittext in which some text are selected . I want to get only selected text from edittext on click of button .

Please suggest me usable link or sample code.

相关标签:
2条回答
  • 2021-02-07 21:29
    EditText et=(EditText)findViewById(R.id.edit);
    
    int startSelection=et.getSelectionStart();
    int endSelection=et.getSelectionEnd();
    
    String selectedText = et.getText().toString().substring(startSelection, endSelection);
    
    0 讨论(0)
  • 2021-02-07 21:50
    getSelectionStart()
    getSelectionEnd()
    

    see this link

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