有系统actionbar

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//先给Activity注册界面进度条功能
setContentView(R.layout.main);//布局
setProgressBarIndeterminateVisibility(true);//在需要显示进度条的时候调用这个方法
setProgressBarIndeterminateVisibility(false);//在不需要显示进度条的时候调用这个方

这样的方式,出来的progressbar是圈圈。

没有系统actionbar

这个时候就要自己去创建progressbar了。自定义一个webview,这个webview中有progressbar。

public class ProgressWebView extends WebView {

    private ProgressBar progressbar;

    public ProgressWebView(Context context, AttributeSet attrs) {
super(context, attrs);
progressbar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
progressbar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 3, 0, 0));
addView(progressbar);
// setWebViewClient(new WebViewClient(){});
setWebChromeClient(new WebChromeClient());
} public class WebChromeClient extends android.webkit.WebChromeClient {
@Override
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);
} } @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);
}
}

使用

public class WebActivity extends BaseActivity {

    private ProgressWebView webview;
private String url;
private String name; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web); // 获取参数
url = getIntent().getStringExtra("url");
name = getIntent().getStringExtra("name"); //绑定控件
webview = (ProgressWebView) findViewById(R.id.webview); //设置数据
titleText.setText(name);
webview.getSettings().setJavaScriptEnabled(true);
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(url);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <com.yydcdut.webdemo.ui.ProgressWebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </LinearLayout>

我是天王盖地虎的分割线

如果加载的页面有需要下载文件,需要设置setDownloadListener方法,根据项目实际需求定制。

参考:自定义控件是在转载的,忘记出处,感谢

Android -- WebView进度条的更多相关文章

  1. android的进度条使用

    android的进度条 1.实现的效果 2.布局代码 先写一个my_browser.xml文件 存放WebView <?xml version="1.0" encoding= ...

  2. Android 设置进度条背景

    Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...

  3. android 自定义进度条颜色

    android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程!   这个没法了只能看源码了,还好下载了源码, sources\b ...

  4. Android之进度条2

    我之前有写过一篇“Android之进度条1”,那个是条形的进度条(显示数字进度),这次实现圆形进度条. 点击查看Android之进度条1:http://www.cnblogs.com/caidupin ...

  5. android多线程进度条

    多线程实现更新android进度条. 实例教程,详细信息我已经注释   android多线程进度条   01package com.shougao.hello; 02 03import android ...

  6. 最简单的android自定义进度条样式

    一.自定义圆形进度条样式 1.在安卓项目drawable目录下新建一个xml文件如下:<?xml version="1.0" encoding="utf-8&quo ...

  7. Android多种进度条使用详解

    在这里,总结一下loading进度条的使用简单总结一下. 一.说起进度条,必须说说条形进度条,经常都会使用到嘛,特别是下载文件进度等等,还有像腾讯QQ安装进度条一样,有个进度总给人良好的用户体验. 先 ...

  8. android ProgressBar 进度条的进度两端是圆角的方法

    转自 http://www.jianshu.com/p/6e7ea842d5ce 另外工作原理可以参考http://blog.csdn.net/lan603168/article/details/44 ...

  9. Android -- ProgressBar(进度条的使用)

    我们在开发程序是经常会需要软件全屏显示.自定义标题(使用按钮等控件)和其他的需求,今天这一讲就是如何控制Android应用程序的窗体显示. requestWindowFeature可以设置的值有:(具 ...

随机推荐

  1. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

  2. API网关的设计思路及落地 IT大咖说 - 大咖干货,不再错过

    API网关的设计思路及落地 IT大咖说 - 大咖干货,不再错过   http://www.itdks.com/dakashuo/new/dakalive/detail/1407

  3. Keil debugging techniques and alternative printf (SWO function)

    One of the basic needs of the embedded software development through the terminal to output debugging ...

  4. STM32F1XX devices vector table for EWARM toolchain.

    ;******************** (C) COPYRIGHT 2014 STMicroelectronics ******************* ;* File Name : start ...

  5. Oracle数据库日期范围查询的两种实现方式

    参考文档:http://database.51cto.com/art/201108/288058.htm Oracle数据库日期范围查询有两种方式:to_char方式和to_date方式,接下来我们通 ...

  6. Using Dtrace OEL 6.X

    http://www.hhutzler.de/blog/using-dtrace/ http://docs.oracle.com/cd/E37670_01/E38608/html/dt_sdtparg ...

  7. 看opengl 写代码(4) 画一个圆

    opengl 编程指南 P30 以下代码 是 用 直线 连起来 画一个圆. // circle.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...

  8. Managing DbContext the right way with Entity Framework 6: an in-depth guide by mehdime

    UPDATE: the source code for DbContextScope is now available on GitHub: DbContextScope on GitHub. A b ...

  9. delphi udp文件传输

    客户端: unit UnitClient; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...

  10. 在delphi中嵌入脚本语言--(译)RemObjects Pascal Script使用说明(1)(译)

    翻譯這篇文章源於我的一個通用工資計算平台的想法,在工資的計算中,不可避免的需要使用到自定義公式,然而對於自定義公式的實現,我自己想了一些,也在網上搜索了很多,解決辦法大致有以下幾種: 1. 自己寫代碼 ...