How to get selected text from edittext in android?

江枫思渺然 提交于 2020-01-01 02:41:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!