我想构建一个应用程序,我想在其中使用可选择的 TextView。当用户从 TextView 选择一个文本时,他会将这个可选择的文本显示到其他屏幕中。但是当我从 TextView 选择文本时,我无法检索所选文本。我也使用 TextView 的方法。
menu_search = (TextView)findViewById(R.id.menu_search);
menu_search.setTextIsSelectable(true);
如何从可选择的 TextView 中获取选定的文本?
Android 有可能吗?
最佳答案
试试这个
String str = menu_search.getText().toString;
int startIndex = menu_search.getSelectionStart();
int endIndex = menu_search.getSelectionEnd();
String selectedStr = str.subString(startIndex, endIndex);
关于java - 如何从可选择的 TextView 中获取文本字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703337/