Select text from text field with one click in android

In one touch I want to get a choice to select and copy text from a text image, as shown here.

enter image description here

+3
source share
3 answers

In onClickListener for TextView :

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(yourTextView.getText()); 

ed : answer the question in the comments:

  yourTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO: add your code here } }); 
+2
source

Just set "textIsSelectable" in TextView to true

  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Detail Text" android:id="@+id/txtBody" android:background="@android:color/white" android:gravity="right" android:textColor="@android:color/black" android:textSize="16sp" android:padding="5dp" android:enabled="true" android:textIsSelectable="true"/> 
+2
source

just add this to your TextView xml file:

 android:textIsSelectable="true" 
+2
source

Source: https://habr.com/ru/post/1498796/


All Articles