setPrimaryClip (http://developer.android.com/reference/android/content/ClipboardManager.html) method: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData. newPlainText("label", "Text to copy"); clipboard. setPrimaryClip(clip);
One of these is an integrated clipboard manager. Like Gboard and the Samsung Keyboard, just tap the arrow icon in the top-left corner of your keyboard, and you'll see the Clipboard icon, among others. Tap it to access blocks of text you've copied recently, then you can paste them with one tap.
Advertisements. A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.
Try android:textIsSelectable
.
i.e., android:textIsSelectable="true"
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.
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();
}
});
Requires API 11, Updated Code, previous method is deprecated
Solution for theme full screen without ActionBar
Extend TextView
and in constructor paste following code
this.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager cManager = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData cData = ClipData.newPlainText("text", getText());
cManager.setPrimaryClip(cData);
Util.toast(mContext, string.text_copyed);
return true;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With