如何在Android选定的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?

此弹出菜单是什么?我曾尝试覆盖活动上下文或选项菜单,但没有。我也曾尝试扩展TextView并覆盖它的Context菜单,但没有用,只显示一个普通的对话框上下文菜单,并且此剪切/粘贴菜单不可用。

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.

但是现在我们可以通过api23使用 ACTION_PROCESS_TEXT 来获取它。
将此代码包含在AndroidManifest.xml文件中。

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.

阅读文档以获取更多信息。

Read the documentation for more information.