Android Marshmallow 文本选择选项菜单操作

标签 android copy-paste

您好,我想添加一个全局文本选择监听器,它显示任何选定文本的子菜单。 Android 6 通过新的文本选择监听器允许这样做。

enter image description here

是否可以通过外部应用程序使用此功能,然后填充子菜单?

最佳答案

这个概念被称为 ACTION_PROCESS_TEXT 并在 Android 6 中可用:

在您的 list 中定义一个 Intent 过滤器:

<activity android:name=".YourActivity" 
          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 中处理 Intent :

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
  boolean readonly = getIntent()
  .getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
}

您只能为每个 Activity 定义一个 Action。

Source

Example

关于Android Marshmallow 文本选择选项菜单操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34559992/

相关文章:

android - 无法使用 Firebase 广告 : No static method zzc(Landroid/os/Bundle;

android - 从 android studio 推送后更改提交消息

android - 使用插件 Crosswalk Intel XDK

Android 无法执行 : 64-bit ELF file

wpf datagrid 复制并粘贴您所看到的内容

powershell - 当我在 PowerShell 中粘贴时如何使输入不自动执行

android - 在 android 中查找当前位置(基于图像的搜索应用程序)

excel - 将 Excel 图表复制到 Word 的 VBA 脚本在更高版本的 Word 中不起作用

javascript - 从 Flash 10 开始,是否有通过 JavaScript/Flash 将多组文本复制到剪贴板的新解决方案?

vba - 在excel vba的第一个空列中复制粘贴范围