【Android-WebView】截取内容生成Bitmap
1.在Android 5.0以下与以上,会有不同,产生白屏的问题(5.0以上)
import static android.webkit.WebView.enableSlowWholeDocumentDraw;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
enableSlowWholeDocumentDraw();
}
在Android的setContentView()之前调用,否则有时候也会白屏。
截取内容:
public Bitmap getWebViewContentShot(final View view) {
if (view == null)
return null;
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(measureSpec, measureSpec);
if (view.getMeasuredWidth() <= 0 || view.getMeasuredHeight() <= 0) {
return null;
}