select & copy to clipboard in TextView in Android

不羁岁月 提交于 2019-12-02 12:02:19

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.

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

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

I think that starting with Lollipop, this actually works as you'd expect it (tested on my app, after I've changed a few things) :

I used this library, and changed this attribute for the file "adp_alert_dialog_material.xml", to just have the attribute you've asked about (on a TextView) :

android:textIsSelectable="true"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!