Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write my own context menu for copy & paste?

I'm writing an application with EditText driven widget. and I'd like to create my own copy & paste menu. To replace android default menu on EditText, what should I do? Just overriding long click? or is there another way to implement? Thanks in advance.

like image 228
skysign Avatar asked Feb 09 '10 04:02

skysign


People also ask

How to copy text from txt files in Windows 11 context menu?

To copy all text in TXT files, we usually need to open documents, select content, and press the Ctrl + C hotkey. However, it would be more convenient if Windows 11’s context menu included an option that copies TXT files to the clipboard. Then users could copy text files simply by right-clicking them and selecting a copy context menu option.

How do I create a custom context menu using HTML?

First, we'll create a list of items that will represent our custom context menu using HTML. Then, we'll add a few lines of scss to fresh up our custom menu. Make it look nice and clean. Whenever we right click to view a context menu on our page, an event is triggered. The event name is (you guessed it right) contextmenu. Crazy right? Not so much.

What is a context menu in Linux?

A context menu is a menu in a GUI that appears upon user interaction, such as a right-click mouse operation. A context menu offers a limited set of choices that are available in the current state, or context, of the operating system or application. Usually the available choices are actions related to the selected object.

How do I deploy a context menu?

In a web browser, when a right-click action is performed, an event gets fired. This event is the contextmenu event. To deploy a customized context menu, we’ll need to prevent default behaviour, and then set up, trigger, and position our own menu.


1 Answers

EditText should already have a context menu enabled. If it were not, then you would have to enable it by calling registerForContextMenu. Once you have the context menu enabled, you have to add items to it. This is done in onCreateContextMenu by using one of the Menu.add methods.

The hard part is writing the code for onContextItemSelected after the user has selected an option. Saving text to the clipboard is simply a matter of calling ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText("myText");. However, first we need to find what text to copy. I haven't figured this last part out yet, but I am hopeful that I will soon.

Related Questions

  • Show context menu when link is long pressed in TextView
like image 111
Casebash Avatar answered Oct 11 '22 17:10

Casebash