Honeycomb WebView上的黑色闪烁

时间:2011-08-17 18:50:40

标签: android

在Honeycomb设备上的WebView中使用<input type="password">字段时遇到问题。每次滚动视图时,一旦滚动结束,屏幕会闪烁黑色,甚至可以保持全黑(除了它将绘制聚焦的密码字段)。我已经在我检查过的所有三款Honeycomb平板电脑上看到了这一点。

我可以在浏览器应用中加载相同的HTML,但我没有看到此问题。我已经尝试更改WebView的WebSettings / WebChromeClient / WebViewClient上的许多设置,并且没有运气。我已将下面的代码加载到Froyo平板电脑上并且没有出现此问题,因此它似乎是一个Honeycomb特定问题。

有没有人见过这个?我目前无法解决或解决这个问题。

这是一个重现问题的简短代码示例。只需关注密码字段并向上和向下滚动即可。有一个密码类型输入字段和一个文本类型输入字段,只是为了表明文本类型字段不会出现问题。 <div>标记只是为了让您更容易滚动并查看问题,但问题仍然在没有<div>标记的情况下发生。

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);
    }
}

4 个答案:

答案 0 :(得分:6)

在尝试了这里建议的所有内容之后,这终于在所有手机上为我工作了:

android:hardwareAccelerated="true"

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

如果您找到一部不起作用的手机,请告诉我。 适用于这些手机:

  • note2(4.1.2)
  • htc one x(4.0.4)
  • galaxy s3(4.3)
  • nexus4(4.3)

答案 1 :(得分:3)

这是蜂窝设备中的已知问题。

然而这个对我有用 -

Compatibility.getCompatibility().setWebSettingsCache(webSettings);

确保实现兼容性层,因为以下方法在SDK_INT&lt;中不起作用11。

webViewInstance.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

建议的解决方案列表为here.

答案 2 :(得分:0)

这听起来像是android:cacheColorHint问题。尝试在WebView的属性集中将其设置为透明。

答案 3 :(得分:0)

对于我来说,xml布局文件中的android:layer="software"工作正常。

相关问题