在EditText能否侦听到选择文本?

vnking 2015-04-09 02:56:55
在EditText中,如果有一段文字,通过长按某一点出现两个尖嘴,拉动会改变选中的文本范围。

问题是:能不能侦听到拉动了两个尖嘴,选中的文字变化了?
...全文
114 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hare_ 2015-04-09
  • 打赏
  • 举报
回复
引用 4 楼 vnking 的回复:
[quote=引用 3 楼 hjq2013 的回复:] [quote=引用 2 楼 vnking 的回复:] 退一步,即使在选择过程中不能侦听,通过一个按钮操作,能不能取出编辑框中选中的内容?
可以的,/** * Convenience for {@link Selection#getSelectionStart}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionStart() { return Selection.getSelectionStart(getText()); } /** * Convenience for {@link Selection#getSelectionEnd}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionEnd() { return Selection.getSelectionEnd(getText()); } 调用这两个方法得到选中的下标,即可拿到选中的文字![/quote] 谢谢!![/quote]不客气,
vnking 2015-04-09
  • 打赏
  • 举报
回复
引用 3 楼 hjq2013 的回复:
[quote=引用 2 楼 vnking 的回复:] 退一步,即使在选择过程中不能侦听,通过一个按钮操作,能不能取出编辑框中选中的内容?
可以的,/** * Convenience for {@link Selection#getSelectionStart}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionStart() { return Selection.getSelectionStart(getText()); } /** * Convenience for {@link Selection#getSelectionEnd}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionEnd() { return Selection.getSelectionEnd(getText()); } 调用这两个方法得到选中的下标,即可拿到选中的文字![/quote] 谢谢!!
Hare_ 2015-04-09
  • 打赏
  • 举报
回复
引用 2 楼 vnking 的回复:
退一步,即使在选择过程中不能侦听,通过一个按钮操作,能不能取出编辑框中选中的内容?
可以的,/** * Convenience for {@link Selection#getSelectionStart}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionStart() { return Selection.getSelectionStart(getText()); } /** * Convenience for {@link Selection#getSelectionEnd}. */ @ViewDebug.ExportedProperty(category = "text") public int getSelectionEnd() { return Selection.getSelectionEnd(getText()); } 调用这两个方法得到选中的下标,即可拿到选中的文字!
vnking 2015-04-09
  • 打赏
  • 举报
回复
退一步,即使在选择过程中不能侦听,通过一个按钮操作,能不能取出编辑框中选中的内容?
Hare_ 2015-04-09
  • 打赏
  • 举报
回复
可以搜索android粘贴板内容看看

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧