如何在全球长按Contextmenu上添加自定义项目,例如Translate和Wikipedia [英] How to add custom item on Global long press Contextmenu like Translate and Wikipedia

查看:70
本文介绍了如何在全球长按Contextmenu上添加自定义项目,例如Translate和Wikipedia的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Google翻译和Wikipedia应用如何长按将其添加到Webview中上下文菜单。
P.S.此屏幕快照来自Nexus 5 6.0.1版本。

I want to know how google translate and wikipedia app did to add their item on the webview long press context menu. P.S. This screenshot is from Nexus 5 6.0.1 version.

推荐答案

他们添加了支持 ACTION_PROCESS_TEXT 通过< intent-filter>

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

关于传送给活动的 Intent (通过 getIntent())获得的 EXTRA_PROCESS_TEXT 将保存一些文本,或者 EXTRA_PROCESS_TEXT_READONLY 将保留它。当用户选择启动此活动的菜单选项时,文本将突出显示。

On the Intent delivered to the activity (obtained via getIntent()), EXTRA_PROCESS_TEXT will hold some text, or EXTRA_PROCESS_TEXT_READONLY will hold it if the text is read-only. The text will be what was highlighted when the user chose the menu option that started this activity.

该活动将通过 startActivityForResult()<调用/ code>。结果 Intent 可以具有自己的 EXTRA_PROCESS_TEXT 值,它将作为替换文本。

The activity will be invoked via startActivityForResult(). The result Intent can have its own EXTRA_PROCESS_TEXT value, which will be the replacement text.

这篇关于如何在全球长按Contextmenu上添加自定义项目,例如Translate和Wikipedia的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆