Copy and paste Android text and android text
Android provides a simple copy and paste function. The code is simple.
Copy the text code:
ClipboardManager cbm = (ClipboardManager) MainActivity. this. getSystemService (Context. CLIPBOARD_SERVICE); cbm. setText ("Text to be copied ");
Code for pasting text:
ClipboardManager paste = (ClipboardManager) MainActivity.this .getSystemService(Context.CLIPBOARD_SERVICE); String content=plaster.getText().toString();
But after the API11 copy and paste is different, in fact, is the problem of the package, see the http://www.apkbus.com/android-174549-1-1.html
Paste the original text here
【
In the previous project, there was a copy and paste function. However, there were differences between the copy and paste functions after api11, and there were only a part of them online. Now I will share them with you;
Public void onClick (View v ){
// TODO Auto-generated method stub
Switch (v. getId ()){
Case R. id. top_back:
Finish ();
Break;
Case R. id. btn_invited_copy:
Int sdkInt = Build. VERSION. SDK_INT;
If (sdkInt> Build. VERSION_CODES.HONEYCOMB) {// api11
ClipboardManager copy = (ClipboardManager) ActMyInvitationCode. this
. GetSystemService (Context. CLIPBOARD_SERVICE );
Copy. setText (invitationCode );
Toast. makeText (ActMyInvitationCode. this, "the invitation code is successfully copied to the Clipboard ",
Toast. LENGTH_SHORT). show ();
} Else if (sdkInt <= Build. VERSION_CODES.HONEYCOMB ){
Android. text. ClipboardManager copyq = (android. text. ClipboardManager) ActMyInvitationCode. this
. GetSystemService (Context. CLIPBOARD_SERVICE );
Copyq. setText (invitationCode );
Toast. makeText (ActMyInvitationCode. this, "the invitation code is successfully copied to the Clipboard ",
Toast. LENGTH_SHORT). show ();
}
Break;
}
}
Some children's shoes have not yet seen the difference. android. content. ClipboardManager was used after api 11, while android. text. ClipboardManager was used before api11;
】