我正在使用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()
http//
file://
工作正常,但不适用于{{1}}。这有什么帮助???
答案 0 :(得分: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();
}
}
});