问题
I want to copy some text in temprory memory :
TextView tv = (int)findViewById(R.id.txt);
String str = tv.getText().toString();
now how an I copy str in clipboard ???
回答1:
Use ClipboardManager
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText("text to clip");
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("text label","text to clip");
clipboard.setPrimaryClip(clip);
}
回答2:
you have to use ClipboardManager
.
here the doc.
you have to call setPrimaryClip
with a ClipData
回答3:
You may need ClipboardManager and perhaps this could help.
来源:https://stackoverflow.com/questions/16435151/how-to-copy-a-text-to-the-clipboard-in-android