我在操作栏中(夏洛克操作栏)中的刷新按钮变得不可见。但是,我不知道如何在我的函数内部调用操作栏更新(onPrepareOptionsMenu()
或InvalidateOptionsMenu()
)makeupdate()
(我需要在函数内部调用)。我已经在 stackoverflow 和谷歌搜索了几个小时......测试了所有但一无所获......
我的makeupdate()
功能:
public void makeupdate(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
MenuItem item = menu.findItem(R.id.refresh);
item.setVisible(false);
}
编辑 - 我的代码
public class SiteActivity extends SherlockActivity {
private WebView myWebView;
final Activity MyActivity = this;
com.actionbarsherlock.app.ActionBar actionbar;
private Menu mainMenu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionbar.setTitle("APP");
actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
setContentView(R.layout.site);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.loadUrl("file:///android_asset/noconnection.html");
myWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
MyActivity.setProgress(progress * 100);
}
});
myWebView.setWebViewClient(new SiteActivityClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
myWebView.loadUrl("file:///android_asset/noconnection.html");
}
});
}
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void makeupdateshowToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
mainMenu.findItem(R.id.refresh).setVisible(false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.layout.actionbar, menu);
mainMenu = menu;
return true;
}
}