WebView.draw()无法正常工作在最新的Andr​​oid系统的WebView更新 [英] WebView.draw() not properly working on latest Android System WebView Update

查看:535
本文介绍了WebView.draw()无法正常工作在最新的Andr​​oid系统的WebView更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 WebView.draw()拿整个的WebView的截图并保存到一个位图(基于中的这个解决方案)。它完美地工作,直至现在。

I'm currently using WebView.draw() to take a screenshot of the entire WebView and save it into a Bitmap (based off of this solution). It has worked perfectly up until now.

我最近测试这个功能在一台Nexus 5(请注意,Nexus的5所讨论的web视图大于屏幕,让用户可以滚动横向和纵向)上运行棒棒堂5.1和Android的最新更新系统的WebView(版本42.0.2311.137在写作的时候),当我注意到,生成位图是错误的。它有正确的尺寸,但不是整体呈现出的WebView,它只有那是可见的,当该方法被称为用户的web视图的一部分。

I was recently testing this functionality on a Nexus 5 (please note that on the Nexus 5 the WebView in question is bigger than the screen, so the user can scroll both horizontally and vertically) running Lollipop 5.1 and the latest update of Android System WebView (version 42.0.2311.137 at time of writing) when I noticed that the generated bitmap was wrong. It had the correct dimensions but instead of showing the whole WebView, it only had the part of the WebView that was visible to the user when the method was called.

我试图卸载所有更新到了Android系统的WebView(从而把它带回39版本(1743759-ARM),并与出厂版本的功能正常工作。所以这个问题是由于一个相对较新的Andr​​oid系统更新系统的WebView,我没能找到一个更改日志,所以我不能弄清楚发生了什么变化,以及如何解决它。 下面是一个快速直观的解释:

I have tried uninstalling all updates to the Android System WebView (thus bringing it back to version 39 (1743759-arm) and with the factory version the functionality works fine. So this problem is due to a relatively recent update of the Android System WebView. I wasn't able to find a change log so I can't figure out what has changed and how to fix it. Below is a quick visual explanation:

有没有其他人遇到这个问题,并找到了一个可能的解决方案?

Has anyone else encountered this problem and found a possible solution ?

推荐答案

您需要调用<一个href="http://developer.android.com/reference/android/webkit/WebView.html#enableSlowWholeDocumentDraw()">WebView.enableSlowWholeDocumentDraw()在创建任何WebViews。也就是说,如果你在你的布局任何WebViews,请确保您调用这个方法的的调用的setContentView()的onCreate()

You need to call WebView.enableSlowWholeDocumentDraw() before creating any WebViews. That is, if you have any WebViews in your layout, make sure you call this method before calling setContentView() in your onCreate().

这篇关于WebView.draw()无法正常工作在最新的Andr​​oid系统的WebView更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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