Context Menu on Android WebView

狂风中的少年 提交于 2019-11-29 21:33:52

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/3211980/context-menu-on-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!