how to make TextView selectable under api 11
Asked Answered
D

2

1

I need to have a text that will be shown to the user, and it will be possible to select a part of it and copy it to the clipboard. But without the keyboard open. I know that on api 11 and newer i can just use

text.setTextIsSelectable (true);

But what is the solution to lower OS versions?

Dukedom answered 23/4, 2013 at 10:44 Comment(7)
you mean testview clickable?Loring
no. i mean that the user can choose part of the text that was shown in TextView and can copy it to paste it to the clipboard.Dukedom
setTextIsSelectable() works fine for HoneyComb+Cassilda
and what about under api 11.Dukedom
#6625800Katzir
I solved this problem : #18042808Hexachlorophene
Why not just use and edittext that doesn't allow editing? And theme it like a textviewAzeotrope
C
1

Use ContextMenu and CLIPBOARD_SERVICE:

private TextView mTextView;

protected final void onCreate(Bundle savedInstanceState) {
...
registerForContextMenu(mTextView);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
        TextView textView = (TextView) view;
        menu.setHeaderTitle(textView.getText()).add(0, 0, 0, R.string.menu_copy_to_clipboard);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText(mTextView.getText());
    return true;
}
Cassilda answered 23/4, 2013 at 11:28 Comment(1)
Is there a way to allow the user to select part of the text? and not all of the text, as you suggested in your solution. So I allow him to experience normal use of copy text.Dukedom
H
0

After a long and time consuming search, I can't find a component that can select text in textview for android API level <=11. I have written this component that may be of help to you : new Selectable TextView in android 3 (API <=11) component

Hexachlorophene answered 4/8, 2013 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.