如何检测页面上的iframe开始加载新页面,以及由于加载时间太长,如何显示加载GIF和图像的加载持续时间。我搜索了同样的答案,但没有一个对我有用。我还根据构建版本将RenderPriority设置为HIGH和setLayerType,但加载时间仍然很长。
我的webview代码
var cts = new CancellationTokenSource();
var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = 8, CancellationToken = cts.Token };
Parallel.For(0, int.MaxValue, parallelOptions, (i) =>
{
var guid = Guid.NewGuid().ToString();
var four = guid.ElementAt(14);
var ab89 = guid.ElementAt(19);
if (four != '4') cts.Cancel();
if (ab89 != 'a' && ab89 != 'b' && ab89 != '8' && ab89 != '9') cts.Cancel();
if ((i % 100000) == 0 && i < (int.MaxValue / 8))
{
Console.WriteLine($"{i * 8:n}"); // roughly
}
});
activity_main.xml
public class MainActivity extends AppCompatActivity {
private WebView webView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT >= 19) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
MyWebViewClient webViewClient = new MyWebViewClient();
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.example.com");
}
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().endsWith(".com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
}
}