的WebView"闪烁"白色背景,如果启用硬件加速(安卓3.0+) [英] WebView "flashing" with white background if hardware acceleration is enabled (Android 3.0+)

查看:416
本文介绍了的WebView"闪烁"白色背景,如果启用硬件加速(安卓3.0+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题与web视图(安卓3.0+),其中的WebView始终显示一个白色的背景前显示我黑色背景(闪烁)。这里是我的简单测试code:

I have an issue with the WebView (Android 3.0+), which the WebView always displays a white background before display my black background ("flashing"). Here is my simple test code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView webView = new WebView(this);
    webView.setBackgroundColor(Color.BLACK);
    setContentView(webView);
    loadWebView(webView);
    webView.loadDataWithBaseURL("localhost://", "<html><head>" +
            "<style>body {background-color: #000}img{max-width:100%}</style></head>" +
            "<body>" +
            "<img src=\"http://developer.android.com/images/practices/actionbar-phone-splitaction.png\" />" +
            "</body></html>", 
            "text/html", "UTF-8", null);
}

我已经尝试了许多解决方案来摆脱这个问题,但不幸运的。

I have tried many solutions to get rid of this problem, but not lucky.

PS:如果硬件加速被关闭就不会出现这个问题。有任何人有同样的问题,解决它?

PS: The problem will not appear if the hardware acceleration is turned off. Have anybody have the same problem and solved it?

感谢你。

推荐答案

我发现这是最有效的修复,的先在这里提到的,是建立一个透明的背景色后的布局已经被夸大:

I found the most effective fix for this, first mentioned here, was to set a transparent background color after the layout has been inflated:

webView.setBackgroundColor(Color.argb(1, 0, 0, 0));

是的,这是一个总的黑客攻击,但它是我发现工作良好,没有禁用硬件加速的唯一解决方案。

Yes, it's a total hack, but it's the only solution I've found to work well without disabling hardware acceleration.

请注意,这确实的不可以的工作,通过设置背景中的XML。

Note that this does not work through setting the background in XML.

这已杰利贝恩得到解决,但也有一些用户报告在奇巧看到这一点。检查您是否具有的没有的禁用硬件加速,如果问题真的消失了,你可能会想包装在一个条件语句code,只针对较旧的设备:

This has been resolved in Jellybean, although some users have reported seeing this in KitKat. Check that you have not disabled hardware acceleration, and if the problem indeed disappears, you will probably want to wrap that code in a conditional statement to only target older devices:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
    webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}

这篇关于的WebView&QUOT;闪烁&QUOT;白色背景,如果启用硬件加速(安卓3.0+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆