How to get selected text from edittext in android?

2019-03-19 04:15发布

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条回答
甜甜的少女心
2楼-- · 2019-03-19 05:01
getSelectionStart()
getSelectionEnd()

see this link

查看更多
小情绪 Triste *
3楼-- · 2019-03-19 05:07
EditText et=(EditText)findViewById(R.id.edit);

int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();

String selectedText = et.getText().toString().substring(startSelection, endSelection);
查看更多
登录 后发表回答