Похоже, что веб-просмотр android 29 вызывает onpagestarted, когда страница видна, поэтому я не могу сделать вывод прогресса, прежде чем сделать страницу видимой, как я это делал в <29.</p>
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
//onpage start
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
//if not first time show the second dialog or else dont show
if (!firsttime) {
loading2.setVisibility(View.VISIBLE);
}
else{
loading2.setVisibility(View.INVISIBLE);
}
is_loading = true;
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
@Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view, url);
//set loading false
is_loading = false;
loading2.setVisibility(View.INVISIBLE);
}
public void onPageFinished(WebView view, String url) {
//set loading false
is_loading = false;
if (firsttime) {
relativeLayout.setVisibility(View.INVISIBLE);
firsttime = false;
}
loading2.setVisibility(View.INVISIBLE);
webView.setVisibility(View.VISIBLE);
}
public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) {
//if error recieve
if (firsttime) {
relativeLayout.setVisibility(View.INVISIBLE);
firsttime = false;
}
loading2.setVisibility(View.INVISIBLE);
view.setVisibility(View.GONE);
webView.loadUrl("file:///android_asset/error.html");
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Opss..")
.setMessage("Sorry, Please try Again !")
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
webView.loadUrl(failingUrl);
iserror = true;
}
})
.setCancelable(false)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
});