如何在文本选择弹出菜单中添加项目? [英] How to add an item to the text selection popup menu?

查看:118
本文介绍了如何在文本选择弹出菜单中添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户标记某些文本时(在EditTextWebView ...之内),将显示一个浮动文本选择弹出窗口,应用程序可在其中添加自定义项目.有人可以给我一个例子,如何将一个项目添加到此弹出菜单中,以显示意图并将所选的String转移到我的活动中.

When the user marks some text (inside of an EditText, WebView...) a floating text selection popup appears, where apps can add custom items. Can someone please give me an example, how to add an item to this popup menu which makes an intent and transfers the selected String to my activity.

推荐答案

此博客教程将向您展示如何:

This blog tutorial will show you how: https://medium.com/google-developers/custom-text-selection-actions-with-action-process-text-191f792d2999

基本上,在您的Manifest文件中,将PROCESS_TEXT intent filter添加到将处理从弹出菜单共享的文本的活动中.

Basically, in your Manifest file, add PROCESS_TEXT intent filter to the activity that will handle the text shared from popup menu.

<activity
    android:name=".ProcessTextActivity"
    android:label="@string/process_text_action_name">
  <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>

然后,您将像这样在Activity中处理该文本

Then, you would process that text in your Activity like this

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.process_text_main);
  CharSequence text = getIntent()
      .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
  // process the text
}

这篇关于如何在文本选择弹出菜单中添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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