我正在寻找一种在每个 Android 版本中从剪贴板复制和粘贴的方法。现在,我只知道如何在 API 11+ 中执行此操作。
copy.setOnLongClickListener(new View.OnLongClickListener()
{
@SuppressLint({ "NewApi", "NewApi" })
@Override
public boolean onLongClick(View v)
{
clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clipdata = ClipData.newPlainText("simple text", copy.getText().toString());
clipboard.setPrimaryClip(clipdata);
Toast.makeText(getApplicationContext(), "Copied to clipboard..", Toast.LENGTH_SHORT).show();
return true;
}
});
paste.setOnLongClickListener(new View.OnLongClickListener()
{
@SuppressLint({ "NewApi", "NewApi" })
@Override
public boolean onLongClick(View v)
{
clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
String pasteData = "";
item = clipboard.getPrimaryClip().getItemAt(0);
pasteData = item.getText().toString();
paste.setText(pasteData);
Toast.makeText(getApplicationContext(), "Pasted", Toast.LENGTH_SHORT).show();
return true;
}
});
我会很感激任何帮助,谢谢。