【问题标题】:Sherlock Actionbar invalidateOptionsMenu()Sherlock 操作栏 invalidateOptionsMenu()
【发布时间】:2013-01-31 16:16:42
【问题描述】:

我在这里犯了一个大错误。 我正在尝试使用 supportInvalidateOptionsMenu(); 更改操作栏菜单但是当函数执行时,应用程序关闭,没有错误。

奇怪的是,在我的 Galaxy Nexus (4.2.2) 上一切正常,但在我朋友的手机 (android 4.0.3) 和我的 android 2.1 模拟器上都不能工作

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
...
actionbar = getSupportActionBar();
...
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.loadUrl(getString(R.string.site_load));
...
}

public class WebAppInterface {
SherlockActivity mActivity;
WebAppInterface(SherlockActivity c) {mActivity = c;}  
public void setrefreshon() {showRefresh = true; mActivity.supportInvalidateOptionsMenu();}
}

有人可以帮助我吗? :/

【问题讨论】:

    标签: android web-applications webview actionbarsherlock


    【解决方案1】:

    这很可能是线程问题。您应该会在主线程之外看到有关 UI 访问的记录错误。也许你正在过滤掉它们?查看完整的日志,而不仅仅是您的包的日志。

    来自Building Web Apps in Webview

    注意:绑定到您的 JavaScript 的对象在另一个 线程而不是在构造它的线程中。

    试试:

    mActivity.runOnUiThread(new Runnable(){
      @Override
      public void run(){
        mActivity.supportInvalidateOptionsMenu();
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多