向剪贴板 ActionBar 添加功能

发布于 2024-12-03 17:54:40 字数 399 浏览 5 评论 0原文

在我的应用程序中,我希望当用户将文本复制到剪贴板时能够启动我自己的功能。

我正在重写 onActionModeFinished 函数,并且因为我想确保用户点击“复制”,所以我正在获取选定的导航索引。不幸的是如果总是返回-1。我在这里做错了什么吗?

@Override
public void onActionModeFinished(ActionMode mode) {
    super.onActionModeFinished(mode);

    if (_actionBar != null) {
        int index = _actionBar.getSelectedNavigationIndex();
        // here index is always -1
    }
}

In my app, I want to be able to start my own function when user copy a text to the clipboard.

I'm overriding function onActionModeFinished and as I want to be sure user tapped on Copy I'm getting selected navigation index. Unfortunately if always return -1. Is there something I'm doing wrong here ?

@Override
public void onActionModeFinished(ActionMode mode) {
    super.onActionModeFinished(mode);

    if (_actionBar != null) {
        int index = _actionBar.getSelectedNavigationIndex();
        // here index is always -1
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2024-12-10 17:54:40

ActionBar 可以在左侧包含选项卡和列表选择器。因此, getSelectedNavigationIndex 用于获取此导航项中的位置,而不是位于右侧的菜单项中的位置。

ActionBar can contain tabs and list selector on the left side. So, getSelectedNavigationIndex is used to get the position in this navigation items not in the menu items located in the right side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文