Search code examples
javascriptactionbarsherlockandroid-webview

WebView and Javascript Interface problems with SherlockActionBar


I have a problem: when I use webview with javascript interface to comunication between my activity and the html page, my actionbarsherlock stop working. And the problem is in this line:

myWebView.addJavascriptInterface(new JsObject(), "injectedObject");

the problems include List navigations and menu items with ActionView .

Basically if I comment the above code, everything works normally.

Some pictures to explain:

My Activity with sherlockactionbar and webview My Activity with sherlockactionbar and webview

My actionbar not working when when I'm calling the method addJavascriptInterface in my webview My actionbar not working when when I'm calling the method **addJavascriptInterface** in my webview

My actionbar working when I remove the method addJavascriptInterface My actionbar working when I remove the method **addJavascriptInterface**

How can I solve this problem???? Thanks.


Solution

  • Oh, I figured out my problem looking at this question

    Basically I had a method accessed by javascript that disguised a view. So this occasioned UI errors.

    Before:

    class JsObject {
       @JavascriptInterface
       public void cancelProgress() {
         progressbar.setVisibility(View.GONE);
      }
    }
    

    After:

    class JsObject {
       @JavascriptInterface
       public void cancelProgress() {
         runOnUiThread(new Runnable(){
         @Override
           public void run(){
            progressbar.setVisibility(View.GONE);
          }
       });
      }
    }