I want to add a button that will copy the text from non-editable textview inside a cardview. Can I use clipboard manager for this?
问问题
7342 次
2 回答
8
try this define variables
private ClipboardManager myClipboard;
private ClipData myClip;
on button click listener
//to copy data to clip board
copy_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
String text;
text = edidata.getText().toString();
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getApplicationContext(), "Text Copied",Toast.LENGTH_SHORT).show();
}
});
i hope this work in your case
于 2017-03-17T09:14:37.833 回答
1
if (android.os.Build.VERSION.SDK_INT > 11) {
android.content.ClipboardManager c = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
c.setPrimaryClip(ClipData.newPlainText("sinaweibo", buildShareCopyContent()));
} else {
android.text.ClipboardManager c = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
c.setText(activitioncode.getText());
}
于 2017-03-17T07:46:43.940 回答