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!
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:
Via a context menu. You can attempt to add menu items to this menu via onCreateContextMenu().
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.
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.
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.
Related
Is it possible to easily show a simple menu, similar to this one in a screenshot from Chrome? I want a menu to show when there is a selection to manipulate to allow the user to Slect All, Cut, Copy, Paste.
Is this a standard control or something that should be easy to get working? What is the name of this control. This control is not showing automatically for our custom EditText view, which is fully functional in every other way.
Will I have to create my own custom control and display it in the correct location, manually? I have done similar work for an equivalent custom control in iOS, where the menu I want is called an Edit Menu, and it is trivial to show and hide that menu.
i want my application to be seen when a user long presses on edit text to copy or paste.
or clicks on copy or paste.
i tried with different intents like
ACTION_PASTE ,
ACTION_EDIT
But none are working for me !!
Please help me out
Thanks in advance.
There is no way for you to automatically appear in the action mode or context menu that appears when the user selects text in an EditText for other applications.
For your own EditText widgets, you can use setCustomSelectionActionModeCallback() to add items to the standard action mode on API Level 11+.
On android, whenever the user long-clicks on a text field, they get a context menu with options like 'copy' , 'paste', 'select all' etc. Now, I'm aware I cannot add my own items to this menu, system-wide - android won't and shouldn't let me. But I can write my own context menu from scratch, and whenever the user long-clicks on a text view, they will be given two options - 1. System context menu 2. My own menu.
I know this can be done, but I don't know what API calls to use, to achieve this.
Existing applications that do something similar:
Swype keyboard: This keyboard application overrides the system keyboard. So when user clicks on a text view to type something, they're given two options, namely - 1. Default system keyboard, or 2. Swype keyboard user installed. User also gets the option to make one of them the default.
Similarly, Go Launcher Ex: System wide whenever we press the 'Home' button, we get two options - to display the regular Home screen, or display the Go Launcher Home screen.
Any suggestions, or reference material are highly appreciated.
Thanks!
Both of your examples are accomplished using Intent filters. However, the EditText's context menu is not shown using an Intent, and therefore cannot be overridden in this way.
You can override the menu in your app using onContextMenu and related API's but there is no way to do so for other apps.
I am trying to build a quick search box. it is basically a widget. Upon clicking, it pops up the quick search box and launch the browser with query string. No activity except searchactivity.
And also added codes for 'recent query suggestion' But having a problem to have menu for 'clear history' Here is what I wanted to implement. When quick search box is displayed, by pressing menu button, I want option menu to be popped up, keypad to be disappeared, quick search box to be stayed.
the implementation of google sample code - Searchable dictionary is not what I want to implement. It starts an activity with instruction message and when a user presses the search button or menu button, it pops up the quick search box. Mine is when it runs from a widget, the quick search box is popped up right away just like the google search widget.
How can I override onCreateOptionMenu on searchmanager? Or is there any way to activate option menu when the searchmanager is activated?
Please take a look at the images below. the second image is what I want to implement upon clicking menu button.
What you need to do is make the search button launch the default search activity when it is pressed. And make it sorta match the existing search dialog style. You can notice this is how the official Twitter client works. You can use apktool (google it) to take a look at the official Twitter clients resource files to get a better idea of how this can be accomplished.
How to open the ContextMenu in Android by Clicking a Button?
A context menu is conceptually similar to the menu displayed when the user performs a "right-click" on a PC. You should use a context menu to provide the user access to actions that pertain to a specific item in the user interface.
On Android, a context menu is displayed when the user performs a "long press" (press and hold) on an item.
Alternatively, if you need a button, you can implement the menu for the view and change the content dynamically.
Your question is bad and you should feel bad, given how readily available (if cryptic) the method behind this process is. This small tutorial helped me greatly.
http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/