<application
android:icon="@drawable/hunqin"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light" >

主题 android:theme------->必须不能使Theme.Light.NoTitleBar

否则不起作用

requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.progressbar);
setProgressBarVisibility(true);
    <application
android:icon="@drawable/hunqin"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
public class ProgressTest extends Activity{

final Activity context = this;

@Override
public void onCreate(Bundle b) {
super.onCreate(b);
requestWindowFeature(Window.FEATURE_PROGRESS);//让进度条显示在标题栏上
setContentView(R.layout.main); WebView webview = (WebView)findViewById(R.id.webview);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//Activity和Webview根据加载程度决定进度条的进度大小
//当加载到100%的时候 进度条自动消失
context.setProgress(progress * 100);
}
});
webview.loadUrl(url);
}

http://www.cnblogs.com/over140/archive/2013/03/07/2947721.html

前言

如果不使用系统自带的TitleBar(即Activity被设置@android:style/Theme.NoTitleBar),那就需要自己来写进度条了,这里封装了一个自定义控件和加载网页的公共Activity,方便使用。

声明

  欢迎转载,但请保留文章原始出处:)

    博客园:http://www.cnblogs.com

    农民伯伯: http://over140.cnblogs.com

正文

一、截图

二、自定义控件

/**
 * 带进度条的WebView
 * @author 农民伯伯
 * @see http://www.cnblogs.com/over140/archive/2013/03/07/2947721.html
 * 
 */
@SuppressWarnings("deprecation")
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);
    }
}

三、加载网页的公共Activity

/**
 * 加载网页的Activity
 * 
 * @author 农民伯伯
 * @see http://www.cnblogs.com/over140/archive/2013/03/07/2947721.html
 * 
 */
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.commom_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);
    }
}

commom_web.xml

<?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" >

<include layout="@layout/include_title" />

<com.nmbb.ui.widget.ProgressWebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

四、补充说明

1、还可以再优化一下,在标题栏加一个刷新按钮。

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

3、自定义控件是在转载的,忘记出处,感谢~~

结束

没啥高深技术,实用就行!

Android中的webview的进度条的更多相关文章

  1. Android笔记(二十三) Android中的ProgressBar(进度条)

    圆形进度条和水平进度条 进度条也是UI界面一种非常实用的组件,通常用于向用户显示某个耗时操作完成的百分比,进度条可以动态的显示进度,避免长时间的执行某个耗时操作时,让用户感觉程序失去了相应,从而更好的 ...

  2. Android中使用WebView, WebChromeClient和WebViewClient加载网页 (能够执行js)

    Android中使用WebView, WebChromeClient和WebViewClient加载网页   在android应用中,有时要加载一个网页,如果能配上一个进度条就更好了,而android ...

  3. WebView线性进度条

    参考:http://www.cnblogs.com/hubli/p/4835549.html APP会跳转网页时候,请参考:http://blog.csdn.net/raphael55/article ...

  4. webview的进度条的加载,webview的使用以及handle的理解与使用

    Webview的几个关键方法要介绍一些: 谷歌官方文档是这么说的; A WebView has several customization points where you can add your ...

  5. android 开发-自定义多节点进度条显示

    看效果图: 里面的线段颜色和节点图标都是可以自定义的. main.xml <RelativeLayout xmlns:android="http://schemas.android.c ...

  6. Android ProgressBar实现加载进度条

    progressBar Android进度条组件.   progressBar的关键属性:      android:max="100"     最大显示进度条      andr ...

  7. Android中脱离WebView使用WebSocket实现群聊和推送功能

    WebSocket是Web2.0时代的新产物,用于弥补HTTP协议的某些不足,不过他们之间真实的关系是兄弟关系,都是对socket的进一步封装,其目前最直观的表现就是服务器推送和聊天功能.更多知识参考 ...

  8. Android 中的 WebView实现 Html5 标签网页加载

    自Android 4.4起,Android中的WebView开始基于Chromium(谷歌浏览器)支持浏览器的一系列功能,webkit解析网页各个节点,这个改变,使得WebView的性能大幅度提升,并 ...

  9. Android中通过WebView控件实现与JavaScript方法相互调用的地图应用

    在Android中通过WebView控件,可以实现要加载的页面与Android方法相互调用,我们要实现WebView中的addJavascriptInterface方法,这样html才能调用andro ...

随机推荐

  1. 使用 Docker 容器应该避免的 10 个事情

    当你最后投入容器的怀抱,发现它能解决很多问题,而且还具有众多的优点: 第一:它是不可变的 – 操作系统,库版本,配置,文件夹和应用都是一样的.您可以使用通过相同QA测试的镜像,使产品具有相同的表现. ...

  2. Asp.Net Mvc+Angular.Js自测小Demo

    参考:http://www.cnblogs.com/eedc/p/6082052.html 一.引用anguler: 1.angular.js 2.angular-route.js 3.app.js ...

  3. 这是一个在Windows live 上实验的文章

    这是一个windows 实验用的文章,希望一次成功

  4. android学习之4种点击事件的响应方式

    如题,下面就一一列出对点击事件响应的4种方式: 第一种:内部类的形式: package com.example.dail; import android.net.Uri; import android ...

  5. cocos2d-x 在mac下执行 demo

    搞了好久,最终成功了. 记录一下 前辈的文章. 依照这个弄的 .http://blog.csdn.net/taowenyin/article/details/11750127 前辈的这个文章是在win ...

  6. 错误处理:java.lang.NoClassDefFoundError: org/apache/taglibs/standard/tag/rt/core/ForEachTag

    在使用JSP.Servlet进行开发时,遇到java.lang.NoClassDefFoundError: org/apache/taglibs/standard/tag/rt/core/ForEac ...

  7. java中说明书/开发文档如何编写?

    由于在java开发时我们得到的或者给别人的文件一般都是class文件,不会给出源文件,故编写一个简洁易懂的说明书是必须的. ps: @param int[] arr 会有警告,可以删掉 int []. ...

  8. linux elinks命令

    Elinks是基于文本的免费浏览器,用于Unix及基于Unix的系统.Elinks支持 HTTP,HTTP Cookies以及支持浏览Perl和Ruby脚本.也很好的支持选项卡浏览.最棒的是它支持鼠标 ...

  9. Linux 机器之间建立互信

    原理: 就是两台机器(web-1和web-2)经过预先设置好经过认证的key文件,双方互相访问时,进行自动认证,从而实现互信.   互信的原理了解了,我们可以把配置ssh互信的步骤进行有效的分割. 1 ...

  10. 简单题思维转化BestCoder

    题意:给你a, b, c, d四个数,这几个数的范围都是大于0小于1000的整数,让比较 a ^b 和 c ^ d的大小. 这道题看着特别简单,但是当时就是做不出来,将近一个月没有做题了,手生了,不过 ...