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

View File

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

View File

@ -3,11 +3,24 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
<RelativeLayout
android:layout_marginTop="@dimen/dp_88"
android:id="@+id/wv"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"