如何清除一个EditText的选择?(How to clear the selection in a

2019-07-30 11:09发布

你如何编程方式删除从选择EditText ? 我试过了:

myEditText.setSelection(selectionEnd);

但只是在创建当前选择的端部的选择0的长度。 我也试过Selection.removeSelection(mySpannable)它只是把空选择在文本的开头。

Answer 1:

调用myEditText.clearFocus(); 。 我认为这是你需要什么



Answer 2:

将选择移动到顶端:

edit_text.setSelection(0);

将选择移动到下:

edit_text.setSelection(edit_text.getText().length());


Answer 3:

EditText message = (EditText) findViewById(R.id.sendText);
String text = message.getText().toString();
message.setText(null);


文章来源: How to clear the selection in an EditText?