Black flickering on Honeycomb WebView

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.

  • Why are build types distinct from product flavors?
  • Adding EditText alongside RadioButton
  • error: cannot find symbol variable abc_ic_ab_back_mtrl_am_alpha
  • Google Play Music API for Android
  • how to use an ArrayAdapter in android of custom objects
  • Implicit “Submit” after hitting Done on the keyboard at the last EditText
  • 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);
        }
    }
    

    Related posts:

    Integration of android ndk&#039;s ndk-gdb with emacs?
    How to add a dynamic view in between items of RecyclerView in android?
    When should I define my Android app as not movable to SD card (installLocation=internalOnly)?
    Android proguard, keep inner class
    How to disable onItemSelectedListener to be invoked when setting selected item by code
    Google Map v2 inside android fragment
  • Drag and Drop icons to Home Screen
  • Issue with cancelling the AlarmManager - PendingIntent
  • How do you set min and max dates in an Android DatePicker?
  • Make text bold and italic
  • How to remove white underline in a SearchView widget in Toolbar Android
  • Open url with an browser
  • 4 Solutions collect form web for “Black flickering on Honeycomb WebView”

    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)

    This is a known issue in honeycomb devices.

    However this one worked for me –

    Compatibility.getCompatibility().setWebSettingsCache(webSettings);
    

    Make sure to implement a Compatibility layer, since following method doesn’t work in SDK_INT < 11.

    webViewInstance.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    

    List of solutions suggested are here.

    This sounds like a android:cacheColorHint issue. Try setting it to transparent in the WebView’s attribute set.

    For me android:layer="software" in the xml layout file works fine.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.