1

我正在使用 Android 4.0。我有一个WebView我想捕捉它的屏幕的地方。我覆盖WebViewClient onPageFinished如下:

@Override
public void onPageFinished(WebView view, String url) {
                Picture picture = view.capturePicture();
Toast.makeText(finplan.this, "picture height "+picture.getHeight()+ " url "+url, Toast.LENGTH_LONG).show();

在另一个程序中,我调用loadUrl()

mywebview.loadUrl("http://www.google.com"); 
// this one works fine and picture.getHeight() is > 0

mywebview.loadUrl("file:///android_asset/test.html"); 
// this one works, but the picture.getHeight() retrieved in onPageFinished is always 0

test.html 是一个简单的 html 文件,后来我注意到任何loadUrl()withhttp//都可以正常工作,但不能在file://. 有什么帮助吗???

4

1 回答 1

0

试试这个方法

webView.setWebViewClient(new WebViewClient() {

    @Override
    public void onPageFinished(WebView view, String url) {
         Picture picture = view.capturePicture();
    }

});
webView.setPictureListener(new PictureListener() {

    public void onNewPicture(WebView view, Picture picture) {
        if (picture != null) {
            Toast.makeText(MainActivity.this,
                    "picture height " + picture.getHeight(),
                    Toast.LENGTH_LONG).show();
        }
    }
});
于 2013-06-25T15:17:02.120 回答