<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. tomcat thread dump 分析【转载】

    前言 Java Thread Dump 是一个非常有用的应用诊断工具, 通过thread dump出来的信息, 可以定位到你需要了解的线程, 以及这个线程的调用栈. 如果配合linux的top命令, ...

  2. Java程序打包

    包名为 com.longneo.data,主程序入口为:com.longneo.data.AppMain 1.到工程目录下 /bin 执行 jar -cvf Demo.jar com 执行完之后会生成 ...

  3. C++ —— 编译程序

    目录: 0.GCC online documentation 1.gcc编译器 常用命令 2.VC编译器  常用参数说明 3.C预处理器命令说明 4.debug 和 release 的区别 0.GCC ...

  4. SpringMVC框架图解析

    Spring框架提供了构造Web应用程序的全能MVC模块.Spring MVC分离了控制器.模型对象.分派器以及处理程序对象的角色,这种分离让它们更容易进行制定.是一个标准的MVC框架. 那你猜一猜哪 ...

  5. js中widow.open()方法详解

    一. window.open() 支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法: window.open(pageURL,nam ...

  6. SKLabelNode类

    继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架  /System/L ...

  7. mongodb3.0 性能測试报告 一

    mongodb3.0 性能測试报告 一 mongodb3.0 性能測试报告 二 mongodb3.0 性能測试报告 三 測试环境: 服务器:X86 pcserver   共6台 cpu:  单颗8核 ...

  8. RHEL7使用ssm命令管理LVM

    1.安装ssm [root@localhost ~]# yum -y install system-storage-manager.noarch  2.检查硬盘和LVM信息 [root@localho ...

  9. Citrix Presentation server can not contact the license server

    If you come across the above error,  you may also come across one or more of the errors below within ...

  10. 解决 iOS webkit 使用CSS动画时闪烁的问题

    -webkit-backface-visibility: hidden;