0

I would like to add a button in android when a user selects texts then clicks the context button (e.g. it shows copy, cut, paste, select all). Can someone please direct me to the libraries or some resource where I can potentially learn about this?

Trying to search for it, I'm kind of lost because I really don't even know where to start. Does android provide a direct library to access this? If so, in what namespace might I find these functions?

Thank you!

Ricky
  • 840
  • 1
  • 8
  • 11

2 Answers2

1

I would like to add a button in android when a user selects texts then clicks the context button (e.g. it shows copy, cut, paste, select all).

There is no "context button" in Android.

On an EditText widget, "Cut, Copy, Paste, Select All" is displayed in one of three ways:

  1. Via a context menu. You can attempt to add menu items to this menu via onCreateContextMenu().

  2. Via an action mode on Android 3.0+. You can call setCustomSelectionActionModeCallback() on the EditText to add new items to the action mode. Note that the action mode is not always displayed, due to either a bug or an inexplicable UI decision.

  3. Via something else, as some Android 2.x device manufacturers elected to do their own thing for cut/copy/paste with an EditText that is not a context menu.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

For copy and paste you can simply use-

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.getText() / clipboard.setText(yourText);

Just implement above lines on click of your button. And this is for Context Menus.

Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • yes, thank you for info on getting/setting clipboard text, but I'd like to actually go one sstep further and insert my own "button" in the clipboard interface. E.G when user selects text, you might have "Cut, Copy, Paste, Select All, RickysButton" – Ricky Mar 27 '12 at 15:46
  • You have that by default in android for the `EditText`. Just press and hold on any `EditText`. – Rajkiran Mar 27 '12 at 16:06