i am using webview in activity and want to use option menu too.
but it does not display option menu on clicking menu button any one guide me what could be the problem?
oncreate
{
_webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//if(_dialog != null && !_dialog.isShowing())
// _dialog.show();
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (_dialog != null && _dialog.isShowing()) {
_dialog.dismiss();
}
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
if (Constants.LOG)
Log.d("recieved error", "");
super.onReceivedError(view, errorCode, description, failingUrl);
try {
if (_dialog != null && _dialog.isShowing())
_dialog.dismiss();
} catch (Exception e) {
}
}
});
_webView.loadUrl(Constants.URL_VOLUNTEER);
}
menu
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 0, Constants.MENU_ITEM_HOME);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0:
Intent intentHomeScreen= new Intent(this,HomeScreen.class);
intentHomeScreen.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentHomeScreen);
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
if(_dialog != null)
_dialog.dismiss();
if(_webView != null)
_webView.stopLoading();
this.finish();
}
return true;
}
There is nothing with
WebViewthat interferes with options menus, AFAIK. I have created activities with aWebViewand an options menu before, though not in around nine months. Remove theWebViewtemporarily — if the options menu still misbehaves, then you have some other issue, such as a malformedonKeyDown()implementation.