import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
import android.widget.ProgressBar;
/**
*/
@SuppressWarnings(“deprecation”)
public class ProgressWebView extends WebView {
private ProgressBar progressbar; /** 进度条 */
public ProgressWebView(Context context, AttributeSet attrs) {
// 初始化进度条
progressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
progressbar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 5, 0, 0));
setWebChromeClient(new WebChromeClient());
}
public class WebChromeClient extends android.webkit.WebChromeClient {
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
progressbar.setVisibility(GONE); // 加载完成隐藏进度条
} else {
if (progressbar.getVisibility() == GONE)
progressbar.setVisibility(VISIBLE);
progressbar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
}
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
LayoutParams lp = (LayoutParams) progressbar.getLayoutParams();
lp.y = t;
progressbar.setLayoutParams(lp);
super.onScrollChanged(l, t, oldl, oldt);
}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:padding=”@dimen/content_padding” >
<app.ui.widget.ProgressWebView
android:id=”@+id/webview“
android:layout_width=“match_parent”
android:layout_height=“match_parent” />
<TextView
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:gravity=“center|center_vertical”
/*******************************************************************************
******************************************************************************/
package app.ui.activity.service;
import mobi.kuaidian.qunakao.R;
import android.content.Intent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import mobi.kuaidian.qunakao.R;
import android.content.Intent;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
原文地址:https://blog.csdn.net/m0_66155658/article/details/122580638
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_22980.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!