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

Android 码拜 9年前 (2015-04-24) 792次浏览 0个评论
 

在EditText中,如果有一段文字,通过长按某一点出现两个尖嘴,拉动会改变选中的文本范围。

问题是:能不能侦听到拉动了两个尖嘴,选中的文字变化了?

在EditText能否侦听到选择文本?
可以搜索android粘贴板内容看看
在EditText能否侦听到选择文本?
退一步,即使在选择过程中不能侦听,通过一个按钮操作,能不能取出编辑框中选中的内容?
在EditText能否侦听到选择文本?
40分
引用 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());
    }

调用这两个方法得到选中的下标,即可拿到选中的文字!

在EditText能否侦听到选择文本?
引用 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());
    }

调用这两个方法得到选中的下标,即可拿到选中的文字!

谢谢!

在EditText能否侦听到选择文本?
引用 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());
    }

调用这两个方法得到选中的下标,即可拿到选中的文字!

谢谢!

不客气,


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明在EditText能否侦听到选择文本?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!