进度条在网页视图 [英] Progress Bar in Webview

查看:258
本文介绍了进度条在网页视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦得到这个进度条正常工作。任何机构可以帮助我的来源,是有什么我思念?

I am having troubles getting this progress bar to work properly. can any body help me with the source, is there something im missing?

 web = (WebView) findViewById(R.id.webview01);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        web.setWebViewClient(new myWebClient());

        //ADDING THIS RESOLVED THE PROGRESS BAR ACTUALLY LOADING.
        web.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
        progressBar.setProgress(progress); } 
        });
        //ADDING THIS RESOLVED THE PROGRESS BAR ACTUALLY LOADING.

        WebSettings websettings = web.getSettings();
        websettings.setBuiltInZoomControls(true);
        websettings.setUseWideViewPort(true);
        websettings.setJavaScriptEnabled(true);
        websettings.setAllowFileAccess(true);
        websettings.setDomStorageEnabled(true);
        websettings.setLoadWithOverviewMode(true);
        websettings.setSavePassword(true);
        web.loadUrl("http://www.google.com");

后来在code

Then Later in the code

    //Loading the Actual Webpage
public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
        progressBar.setVisibility(View.VISIBLE);

    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub

        view.loadUrl(url);
        progressBar.setVisibility(View.VISIBLE);
        return true;

    }
    //web.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
         progressBar.setProgress(progress);

    }




    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        progressBar.setVisibility(View.GONE);
    }

}

web视图自身工作得很好,我只是想有一个水平加载条,类似像海豚,铬等浏览器。

The webview itself works just fine, im just trying to have a horizontal loading bar, similar to browsers like dolphin, chrome, etc.

下面是布局

 <?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:background="@drawable/bgapp"
 android:fadingEdge="horizontal"
 android:gravity="center"
 android:orientation="vertical" >

 <include
    android:id="@+id/inc_blue"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    layout="@layout/inc_enphase_bar_with_title_buttons" />

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:minHeight="8dip" />

<WebView
    android:id="@+id/webview01"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.15"
    android:fadingEdge="vertical" >

</WebView>

林没有得到任何错误或antying所以没有logcat的,它只是实际加载,它会显示进度条,当网页加载,但没有动画或加载。其实运动

Im not getting any errors or antying so no logcat, its just actually loading, it displays the progress bar when a webpage is loading but no animation or actually movement of loading.

推荐答案

您还应该通过设置中间进度

You should also set intermediate progress by using

progressBar.setProgress(int);

有要显示的进度。所有你做的是显示和隐藏视图

for the progress to be shown. All you are doing is showing and hiding the view

编辑:
<击>添加低于code。

Add below code.

   @Override
   public void onProgressChanged(WebView view, int progress) {
     progressBar.setProgress(progress);
   }


对不起,你需要为这个webchromeclient。因此,使用如下。把它放在略低于

Sorry you need a webchromeclient for this. So use like below. Put it just below

web.setWebViewClient(new myWebClient());
//add this below line
web.setWebChromeClient(new WebChromeClient() {
   public void onProgressChanged(WebView view, int progress) {
        progressBar.setProgress(progress);
   }
 });

的WebView 文件,它有一个例子。

Check WebView Doc, it has an example.

这篇关于进度条在网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆