简体   繁体   English

如何禁用 ContextMenu 而不是 WebView 中的右键单击事件

[英]How to disable the ContextMenu but not the right click event in a WebView

I have tried with the setContextMenuEnabled(false) method of the WebView class, but that also disables the right click event an does not pass it to the website, so no javascript events can be triggered.我已经尝试过使用WebView类的setContextMenuEnabled(false)方法,但这也会禁用右键单击事件并且不会将其传递给网站,因此无法触发任何 javascript 事件。

I found other answer that shows how to add more options to the context menu, thing that I do not want to do, I just want to disable the contextMenu but no the event.我找到了其他答案,显示了如何向上下文菜单添加更多选项,这是我不想做的事情,我只想禁用 contextMenu 而不是事件。

create the context menu at runtime within the onCreateContextMenu:
@Override
public void onCreateContextMenu(ContextMenu cmenu, View vw, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(cmenu, vw, menuInfo);

AdapterContextMenuInfo ac = (AdapterContextMenuInfo) menuInfo;
MyObject myobj = (MyObject) myListView.getItemAtPosition(ac.position);

cmenu.setHeaderTitle("Title");  
cmenu.add(0, vw.getId(), 0, "Remove " + myobj.name); 
}

check http://developer.android.com/reference/android/widget/AdapterView.AdapterContextMenuInfo.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM