问题描述
我想知道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 $如果文本是只读的,则c $ c>将保留它。当用户选择启动此活动的菜单选项时,文本将突出显示。
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()。结果
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!