<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 背景 --> <item android:id="@android:id/background"> <shape> <solid android:color="@android:color/transparent" /> </shape> </item> <!-- 进度条 --> <item android:id="@android:id/progress"> <clip> <shape> <solid android:color="@android:color/holo_green_light" /> </shape> </clip> </item> </layer-list>
@SuppressWarnings("deprecation")public class ProgressWebView extends WebView
{
private final static String TAG = ProgressWebView.class.getSimpleName();
private ProgressBar progressBar;
private Context context;
public ProgressWebView(Context context, AttributeSet attrs)
{
super(context, attrs);
this.context = context;
progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
progressBar.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.MATCH_PARENT, 3, 0, 0)); progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.wevbview_progressbar));
addView(progressBar);
setWebChromeClient(new WebChromeClient());
}
public class WebChromeClient extends android.webkit.WebChromeClient
{
@Override
public void onProgressChanged(WebView view, int newProgress)
{
Log.d(TAG, "newProgress" + newProgress);
if (newProgress == 100)
{
progressBar.setVisibility(GONE);
}
else
{
if (progressBar.getVisibility() == GONE)
progressBar.setVisibility(VISIBLE);
progressBar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
// 处理javascript中的console.log
@Override
public boolean onConsoleMessage(ConsoleMessage cm)
{
android.util.Log.d(TAG, "webview console " + cm.lineNumber() + " of " + cm.sourceId() + " : " + cm.message());
return true;
} // 处理javascript中的alert()
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result)
{
result.cancel();
return true;
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
LayoutParams lp = (LayoutParams) progressBar.getLayoutParams();
lp.x = l;
lp.y = t;
progressBar.setLayoutParams(lp);
super.onScrollChanged(l, t, oldl, oldt);
}}
ProgressWebView webView = (ProgressWebView)findViewById(R.id.them_webview);webView.setDownloadListener(new DownloadListener()
{
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
{
if (url != null && url.startsWith("http://"))
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}});webView.loadUrl("http://www.cnblogs.com/hubli/p/4835549.html");
<com.etoury.webviewprogress.ProgressWebView android:id="@+id/them_webview" android:layout_width="match_parent" android:layout_height="match_parent" />
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有