Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we add a new context menu option to all the apps that would show up when user selects a text and long presses on it?

How can we add a new context menu option to all the apps that would show up when user selects a text and long presses on it?

Let's say I want to provide user the capability of finding the meaning of a word from an offline dictionary without having to navigate away from his app context.

  1. In general to add a context menu we would do a registerForContextMenu on a particular TextView object. Given that this needs to work for all the apps, how do we add context menu options?
  2. How to read the selected text?
  3. How to render a pop-up control on top of the currently open app?

I'm quite new to android development. So any detailed answers or pointers to samples will be of great help. I'm assuming this should be possible to do as the apps "define", "define offline dictionary" seem to do something close to this if not exactly same. In these apps, you can select text and click on copy to see the meaning of the text.

All the search that I have done have shown me examples on how to render a context menu for a text view or how to get selected list item in the context menu handler. But that is not helpful.

Thanks in advance.

like image 422
cp1 Avatar asked Feb 21 '17 17:02

cp1


People also ask

How do you bring up a contextual menu?

A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.

How do I create a context menu in react?

Creating a custom right-click menu in React. To create a right-click menu, we need to use the contextmenu event listener. This event fires when the user attempts to open a context menu. It is typically triggered by clicking the right mouse button, or by pressing the context menu keyboard shortcut.

How do you create a context menu in HTML?

The contextmenu global attribute is the id of a <menu> to use as the contextual menu for this element. A context menu is a menu that appears upon user interaction, such as a right-click. HTML now allows us to customize this menu. Here are some implementation examples, including nested menus.


1 Answers

I think this can help you, says how to create the Context menu and get the selected text. with that you just need to do a intent to a dictionary giving that selected text as a extra:

https://nitesh.morajkar.com/how-to-select-and-share-text-with-intents-in-android/

And if you want to use for example the google translator for definitions this can help:

Android API support dictionary applications

EDIT: after some search by both the solution for this question is here: https://medium.com/google-developers/custom-text-selection-actions-with-action-process-text-191f792d2999#.h6377bc8j

like image 165
Joao Jorge Avatar answered Oct 12 '22 03:10

Joao Jorge