Android WebView 上的上下文菜单
我想在整个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.