从后面的代码显示上下文菜单

发布于 2024-09-19 00:29:24 字数 97 浏览 2 评论 0原文

这可能是一个简单的问题,但我一直在寻找答案,但找不到答案。是否有任何代码可以通过代码在 Android 上显示上下文菜单,而不是按菜单按钮?例如,当我触摸屏幕时它会调用上下文菜单?

This might be a simple question, but I've been looking around and can't find the answer. Is there any code to show the context menu on Android from a code, instead of pressing the menu button? E.g. when I touch the screen then it'll call the context menu?

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

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

发布评论

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

评论(4

半窗疏影 2024-09-26 00:29:25

使用。

view.showContextMenu();

您可以在您的视图上

You can use

view.showContextMenu();

on your view.

海拔太高太耀眼 2024-09-26 00:29:24

每当您想要打开 Activity 时,都可以调用 openContextMenu()。请注意,这是一种相当不寻常的 UI 模式,您的用户可能没有想到。

Call openContextMenu() on your Activity whenever you want to open it. Note that this is a rather unusual UI pattern, one that your users may not expect.

梦归所梦 2024-09-26 00:29:24
 OnClickListener onClick_Show_Contextmenu = new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) context).openContextMenu(v);
            }

        };

        findViewById(R.id.xxx).setOnClickListener(onClick_Show_Contextmenu);

        registerForContextMenu(findViewById(R.id.xxx));
        findViewById(R.id.xxx).setLongClickable(false);
 OnClickListener onClick_Show_Contextmenu = new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) context).openContextMenu(v);
            }

        };

        findViewById(R.id.xxx).setOnClickListener(onClick_Show_Contextmenu);

        registerForContextMenu(findViewById(R.id.xxx));
        findViewById(R.id.xxx).setLongClickable(false);
绝情姑娘 2024-09-26 00:29:24

您可以使用以下任意一项:

  1. < strong>openContextMenu 如下所示:
registerForContextMenu(view); 
打开上下文菜单(视图);
取消注册ForContextMenu(视图);
  1. setOnCreateContextMenuListener

  2. showContextMenuForChild

you can use any of the following:

  1. openContextMenu as shown here:
registerForContextMenu(view); 
openContextMenu(view);
unregisterForContextMenu(view);
  1. setOnCreateContextMenuListener

  2. showContextMenuForChild

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