Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add item into popup copy/paste menu on a android selected textview?

please look this screenshot. In normal case, when text be selected, a popup menu opened, but only have cut/paste item. I want to know, how to add item just like this "web search / share" into this popup menu?

What's this popup menu? I had tried to override Activity Context or Option Menu, but it' not. I had also tried to extends TextView and override it's Context menu, but no use, only show a normal dialog context menu, and this cut/paste menu disappered.

enter image description here

like image 692
hyyou2010 Avatar asked Dec 23 '15 16:12

hyyou2010


1 Answers

Before the api23,I have no ideal too. But now we can get it use ACTION_PROCESS_TEXT with api23. Include this code in the AndroidManifest.xml file.

 <activity
        android:name=".YourActivity">
        <intent-filter>
            <action android:name="android.intent.action.PROCESS_TEXT" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
</activity>

Install your app, then you can find your app name in the text selection menu.

Sample

Read the documentation for more information.

like image 192
jinsihou Avatar answered Oct 05 '22 16:10

jinsihou