0
我想要在後臺加載webview並只顯示它加載的頁面的位圖。我在我的視圖層次結構中具有可見性設置爲「不可見」的webview和我希望顯示webview的位圖的imageview。Android - 顯示背景WebView作爲位圖
imageView = (ImageView)findViewById(R.id.imageview);
webView = (WebView)findViewById(R.id.webview);
webView.setBackgroundColor(Color.parseColor("#006330"));
webView.setDrawingCacheEnabled(true);
webView.loadDataWithBaseURL(SiteAPI.URL, html, "text/html", "iso-8859-1", null);
webView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight());
Bitmap b = webView.getDrawingCache();
webView.setDrawingCacheEnabled(false);
if(b != null) {
Toast.makeText(getBaseContext(), "Not null", Toast.LENGTH_LONG).show();
imageView.setImageBitmap(Bitmap.createBitmap(b));
}
else {
Toast.makeText(getBaseContext(), "Null.", Toast.LENGTH_LONG).show();
}
getDrawingCache()的調用每次都返回null。我試過setContentView(webView),頁面顯示正常。我確定isDrawingCacheEnabled()返回true,但位圖仍然爲空。我哪裏錯了?