How to get Android Webview to repaint DOM changes?

I am currently working on a web portal that needs to be run on Android Webview as part of its own application. This entire portal is heavily based on AJAX. Therefore, whenever a form is submitted, it runs asynchronously. Depending on the answer, I need to present a window with the message “Success” or “Error”. I am doing this with jQuery at the moment. The problem is that Android Webview will not redraw, and therefore the message box will not be visible. Which helps, you need to click anywhere on the screen. It seems to make it repaint. No, what do I need to do:

1) Changing the DOM in a different way, so Android Webview handles it correctly.

OR

2) Force repainting by triggering some (pseudo) events or using dirty hacking :)

Has anyone ever experienced this problem? Any tips are greatly appreciated.

+5
source share
4 answers

Watch this video and read this answer . The trick is to use

    -webkit-transform: translate3d(0,0,0);

css style in div to be updated. This creates a new layer, and animations / updates become smoother.

+4
source

DOM , , , , (WebView.addJavascriptInterface()) - Webview ?

+1

, :

jQuery, JavaScript WebView? , JavaScript WebView (, , jQuery ).

myWebView.getSettings().setJavaScriptEnabled(true);
+1

webview , . ://WEBVIEW

package com.example.scroll;
// philip r brenan at gmail.com, www.appaapps.com 
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

public class MainActivity extends Activity
 {protected void onCreate(Bundle savedInstanceState)
   {super.onCreate(savedInstanceState);
    setContentView(new MyWebView(this)); 
   }
  class MyWebView extends WebView 
   {MyWebView(Context Context)
     {super(Context);
      getSettings().setJavaScriptEnabled(true);
      addJavascriptInterface(this, "Android");   
      new Thread()
       {public void run()
         {for(int j = 0; j < 100; ++j)
           {post(new Runnable()
             {public void run()
               {loadData(content(), "text/html", "utf-8"); // Display in browser
               }
             });    
            try {Thread.sleep(5000);} catch(Exception e) {}
           }  
         }
       }.start();
     } 
    int c = 0, C = 1;
    String content() 
     {final StringBuilder s = new StringBuilder();
      //s.append("<html id="+(C++)+"><body>"); // WEBVIEW REFRESHES CORRECTLY *************** 
      s.append("<html><body>");              // WEBVIEW DOES NOT REFRESH ******************

      s.append("<h1 id=11>1111</h1>");
      s.append("<script>location.href = '#22';</script>");
      for(int i = 0; i < 10; ++i) s.append("<p>"+c+c+c); ++c;

      s.append("<h1 id=22>2222</h1>");
      for(int i = 0; i < 10; ++i) s.append("<p>"+c+c+c); ++c;
      Log.e("AAAAAA", "content="+s.toString());
      s.append("</body></html>");
      return s.toString();
     }
   } 
 } 
+1
source

All Articles