Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select + copy text in a TextView?

Tags:

android

Is there a way to allow the user to select / copy text in a TextView? I need the same functionality of EditText where you can long-press the control and get the popup options of select all / copy, but I need the control to look like a TextView.

Tried a few things like making an EditText use the editable="none" option or inputType="none", but those still retain the framed background of an EditText, which I don't want,

Thanks

------- Update ----------------------

This is 99% there, all I'd want is for the selection hilight to be visible (the orange stuff). Other than that it's good, could live with this though:

<EditText    android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:editable="false"   style="?android:attr/textViewStyle"   android:textColor="@color/white"   android:textAppearance="@android:style/TextAppearance.Medium"   android:cursorVisible="false"   android:background="@null" /> 

I guess it's being caused because of cursorVisible="false" but without that the cursor is present even without any selection being made.

like image 762
user291701 Avatar asked May 17 '11 03:05

user291701


1 Answers

android:textIsSelectable works (at least in ICS - I haven't yet checked in earlier versions)

<TextView     android:id="@+id/deviceIdTV"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:textIsSelectable="true"     android:text="" /> 
like image 99
Milind Avatar answered Oct 12 '22 01:10

Milind