Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black flickering on Honeycomb WebView

Tags:

android

I've run into a problem when using <input type="password"> fields in a WebView on Honeycomb devices. Any time the view is scrolled, the screen flickers black and can even stay all black (except that it will draw the focused password field) once scrolling ends. I've seen this on all three Honeycomb tablets I've checked.

I can load the same HTML in the Browser app and I do not see this issue. I've tried changing many of the settings on the WebSettings/WebChromeClient/WebViewClient of the WebView and had no luck there. I've loaded the code below on a Froyo tablet and this issue did not occur, so it seems like a Honeycomb specific issue.

Has anyone seen this before? I'm at a loss on how to fix or workaround this issue currently.

Here's a short code sample that reproduces the issue. Simply focus the password field and scroll up and down. There's a password type input field and a text type input field, just to show that the issue does not occur with the text type field. The <div> tag is there simply to make it easier to scroll around and see the issue, although the issue still occurs without the <div> tag.

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class PasswordFieldTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView webview = new WebView(this);
        String html = "<html><body><div style=\"with: 120%; height: 200%; border: 20px dashed black;\">" +
            "Password: <input type=\"password\" name=\"passfield\"/><br/>" +
            "Text: <input type=\"text\" name=\"textfield\"/>" +
            "</div></body></html>";
        webview.loadData(html, "text/html", "utf-8");

        setContentView(webview);
    }
}
like image 800
Luke Phillips Avatar asked Aug 17 '11 18:08

Luke Phillips


1 Answers

After trying everything suggested here, this finally worked for me on all the phones:

android:hardwareAccelerated="true"

AND:

if (android.os.Build.VERSION.SDK_INT < 16) {
 webView.setBackgroundColor(0x00000000);
} else {
 webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}

Please let me know if you find a phone this doesn't work on. Works with these phones:

  • note2 (4.1.2)
  • htc one x (4.0.4)
  • galaxy s3 (4.3)
  • nexus4 (4.3)
like image 64
Erik B Avatar answered Oct 06 '22 17:10

Erik B