How do I enable standard copy paste for a TextView in Android?
To enable the standard copy/paste for TextView, U can choose one of the following:
Change in layout file: add below property to your TextView
android:textIsSelectable="true"
In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
And long press on the TextView you can see copy/paste action bar.
Try android:textIsSelectable
.
i.e., android:textIsSelectable="true"
This works for copy pre-Honeycomb:
import android.text.ClipboardManager;
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager cm = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(textView.getText());
Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show();
}
});