选择&复制到Android中的TextView中的剪贴板 [英] select & copy to clipboard in TextView in Android

查看:80
本文介绍了选择&复制到Android中的TextView中的剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以允许用户选择然后在TextView中的剪贴板中复制文本?

Is it possible to allow the user to select and then copy text in the clipboard in a TextView?

我发现,但没有答案。

我有还尝试设置 android:textIsSelectable = true ,但没有用。

I have also tried to set android:textIsSelectable="true" but it didn't work.

推荐答案

我通过使用EditText对其进行了修复,但是为了避免我在回答 imran khan时描述的问题,我在android代码中找到了有关setKeyListener的注释:

I fixed it by using an EditText but to avoid the problems I described in my answer to "imran khan" I found a comment about setKeyListener in the android code:


 * Be warned that if you want a TextView with a key listener or movement
 * method not to be focusable, or if you want a TextView without a
 * key listener or movement method to be focusable, you must call
 * {@link #setFocusable} again after calling this to get the focusability
 * back the way you want it.


所以问题是,当您将标志设置为false时

So the problem is that when you set the flag editable to false setKeyListener is called and the focusable flag is overwritten.

要解决此问题,请在我的活动的onCreate中添加:

To fix it, in the onCreate of my activity I added:

    tesxtView.setKeyListener(null);
    tesxtView.setFocusable(true);

通过这样做,我也消除了拼写错误的单词的标记

By doing this I also got rid of the marks for the wrongly spelled words

这篇关于选择&复制到Android中的TextView中的剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆