Android WebView 上的上下文菜单

发布于 2024-09-08 15:25:45 字数 473 浏览 2 评论 0原文

我想在整个 Android WebView 上添加一个上下文菜单。我有以下代码:

registerForContextMenu(findViewById(R.id.webview));
...
public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   if (v.getId() == R.id.webview) {       
       //display context menu
   }
}

我注意到仅当长按 WebView 呈现的网页中的链接时才会显示上下文菜单。当在 Web 视图的空白区域(网页的空白区域或纯文本区域)长按时,不会显示上下文菜单。

关于如何显示整个网页而不仅仅是链接的上下文菜单有什么想法吗?

I'd like to add a context menu on an entire Android WebView. I have the following code:

registerForContextMenu(findViewById(R.id.webview));
...
public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   if (v.getId() == R.id.webview) {       
       //display context menu
   }
}

I noticed that the context menu is only displayed when a long press is done on a link in the webpage rendered by the WebView. When a long press is done in an empty area of the web view (an empty or text only area of the web page) the context menu is not displayed.

Any idea about how to display a context menu for the entire webpage and not only for links?

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

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

发布评论

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

评论(1

蓝梦月影 2024-09-15 15:25:45

http://developer.android.com/reference/android/view/View .OnLongClickListener.html

看一下 onLongClick(),然后用列表在对话框上实现。

http://developer.android.com/reference/android/view/View.OnLongClickListener.html

Take a look at onLongClick() and then implement on your dialog with a list.

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