webview添加loading

This commit is contained in:
lijia 2024-09-09 15:51:39 +08:00
parent 1d9e8baed8
commit 4ac0511f08
3 changed files with 26 additions and 9 deletions

View File

@ -15,6 +15,7 @@ import android.webkit.WebResourceRequest;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -48,6 +49,7 @@ public class WebActivity extends BaseActivity {
private int id = -1; private int id = -1;
private WebView wv; private WebView wv;
private TextView title_tv; private TextView title_tv;
private ProgressBar progressBar;
private PaxWebChromeClient chromeClient; private PaxWebChromeClient chromeClient;
private ToH5Bean toH5Bean; private ToH5Bean toH5Bean;
@ -59,6 +61,7 @@ public class WebActivity extends BaseActivity {
con=this; con=this;
initHardwareAccelerate(); initHardwareAccelerate();
wv = findViewById(R.id.wv); wv = findViewById(R.id.wv);
progressBar = findViewById(R.id.progressBar);
title_tv = findViewById(R.id.title); title_tv = findViewById(R.id.title);
Intent in = getIntent(); Intent in = getIntent();
url = in.getExtras().getString("url"); url = in.getExtras().getString("url");
@ -66,7 +69,7 @@ public class WebActivity extends BaseActivity {
toH5Bean = (ToH5Bean)in.getSerializableExtra("ToH5Bean"); toH5Bean = (ToH5Bean)in.getSerializableExtra("ToH5Bean");
String carNumber = toH5Bean.getCarNumber(); String carNumber = toH5Bean.getCarNumber();
id = in.getExtras().getInt("id"); id = in.getExtras().getInt("id");
chromeClient = new PaxWebChromeClient(this,null,null); chromeClient = new PaxWebChromeClient(this,progressBar,null);
if ("咨询建议".equals(title)) { if ("咨询建议".equals(title)) {
initOpinion(); initOpinion();
} else { } else {

View File

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.view.View;
import android.webkit.PermissionRequest; import android.webkit.PermissionRequest;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
@ -38,12 +39,12 @@ public class PaxWebChromeClient extends WebChromeClient {
@Override @Override
public void onProgressChanged(WebView view, int newProgress) { public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) { if (newProgress == 100) {
//bar.setVisibility(View.INVISIBLE); bar.setVisibility(View.INVISIBLE);
} else { } else {
// if (View.INVISIBLE == bar.getVisibility()) { if (View.INVISIBLE == bar.getVisibility()) {
// bar.setVisibility(View.VISIBLE); bar.setVisibility(View.VISIBLE);
// } }
// bar.setProgress(newProgress); bar.setProgress(newProgress);
} }
super.onProgressChanged(view, newProgress); super.onProgressChanged(view, newProgress);
} }

View File

@ -3,11 +3,24 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<WebView
<RelativeLayout
android:layout_marginTop="@dimen/dp_88" android:layout_marginTop="@dimen/dp_88"
android:id="@+id/wv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent">
<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="5dp"
android:visibility="invisible"
android:layout_alignParentTop="true" />
</RelativeLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"