我想在我的 webview 运行时单击菜单按钮时调用我的函数 onCreateOptionsMenu 。现在,当您在 Webview 运行时单击 Memnu 按钮时,它会显示一些默认菜单,而不是我的自定义菜单。
我将如何修改下面的代码以禁用默认菜单并显示我的自定义菜单?当 Web 视图未运行时,它会在您单击菜单按钮时显示我的自定义菜单。
public class WebViewActivity extends Activity {
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
final Activity mActivity = this;
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
// SETS DEFAULT MODE TO LANDSCAPE
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Makes Progress bar Visible
getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
Window.PROGRESS_VISIBILITY_ON);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://Google.com");
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
mActivity.setTitle("Google.com");
mActivity.setProgress(progress * 100);
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// do your menu stuff here
return true;
}
else
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, menu);
return true;
}
}