机器人的WebView进度条 [英] Android WebView progress bar

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

问题描述

我已经看过类似这样的<一个问题href="http://stackoverflow.com/questions/2496119/in-an-android-app-i-would-like-to-show-a-progress-bar-on-a-child-tab-until-the-we/2496273#2496273">here但因为我是一个新手,可能有人解释如何得到这个在web视图工作,或者至少如何设置10秒的时间延迟,这样的人都知道,它的加载?

I have looked at a question similar to this here but as I am a newbie could someone explain how to get this to work in a WebView or at least how to set a 10 second time delay so people know that it's loading?

推荐答案

以及用于水平式的,我想你首先需要定义你的进度条,并与您的XML文件中像这样联系起来:

well for horizontal style, I guess you first need to define your progress bar and link it with your xml file like this:

 final ProgressBar Pbar;
 final TextView txtview = (TextView)findViewById(R.id.tV1);
 Pbar = (ProgressBar) findViewById(R.id.pB1);

然后,你可以使用onProgressChanged方法在WebChromeClient:

Then, you may use onProgressChanged Method in your WebChromeClient:

    MyView.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, int progress) 
                   {
                   if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
                       Pbar.setVisibility(ProgressBar.VISIBLE);
                       txtview.setVisibility(View.VISIBLE);
                   }
                   Pbar.setProgress(progress);
                   if(progress == 100) {
                       Pbar.setVisibility(ProgressBar.GONE);
                       txtview.setVisibility(View.GONE);
                   }
                }
            });

在这之后,你的布局,你有这样的事情

After that, in your layout you have something like this

<TextView android:text="Loading, please wait . . ." 
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:id="@+id/tV1" android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:textColor="#000000"></TextView>

<ProgressBar android:id="@+id/pB1"
    style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_centerVertical="true"
    android:padding="2dip">
</ProgressBar>

这是我做到了我的应用程序。我想这样做在使用progressbarLarge以不同的方式,但我不能,因为我失去了一些东西在那里,我不知道。我会很高兴,如果有人在分享他们是如何做到这在progressbarLarge一个web视图中的任何想法。

This is how i did it in my app. i was thinking of doing it in a different way using progressbarLarge but i couldn't because i was missing something there i don't know. I would be happy if someone shares any ideas on how they did this on progressbarLarge inside a webView.

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

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