我想要在Android中的Web視圖截圖。然而,屏幕截圖太快,因此我得到一個空白的截圖。我嘗試實施一個webviewclient和onPageFinished在拍攝之前聽取webview加載,但它沒有奏效。在拍攝截圖之前,如何確保視圖已加載?等待webview加載HTML之前採取屏幕截圖
public void onSaveClicked(View reLayout){
final WebView webview;
setContentView(R.layout.webview);
webview = (WebView) findViewById(R.id.webview);
WriteJsJson();
Activity context;
context = _activity.get();
Intent fire = new Intent(context, WebviewActivity.class);
switch (_reportType) {
case 1 :
fire.putExtra("target", "daily"); // Parameter to tell the webview activity to open the right report.
case 2 :
fire.putExtra("target", "week");
case 3 :
fire.putExtra("target", "month");
}
startActivity(fire);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
grabScreen(); //method for taking screenshot and storing it...
}
});
這段代碼工作完美嗎? –