问题
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.
回答1:
EditText et=(EditText)findViewById(R.id.edit);
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
String selectedText = et.getText().toString().substring(startSelection, endSelection);
回答2:
getSelectionStart()
getSelectionEnd()
see this link
来源:https://stackoverflow.com/questions/10070762/how-to-get-selected-text-from-edittext-in-android