2016-02-26 115 views
0

我想要在webview中加载网站时的进度条。Android Webview加载时的进度条

我搜索的解决方案不满意。

请大家帮帮我吗?

当我点击网页上的任何链接,它加载完美,但我想知道它装载了多少。所以,我需要在webview顶端加载进度条

+0

指定你在寻找什么... Mayby post image? – EliaszKubala

回答

0

创建一个进度视图,当webview加载时(使用onProgressChanged),设置当前进度,完成后隐藏它。

这很容易,那里有解决方案。

编辑:IMO这是Android WebView progress bar重复

+0

请给出任何示例代码 –

+0

http://stackoverflow.com/questions/2537454/android-webview-progress-bar – xdevs23

+0

它工作正常谢谢uuuuuuuuu –

-1

简单的方法是这样的;

 public class MyActivity extends Activity { 
    private static final int PROGRESS = 0x1; 

    private ProgressBar mProgress; 
    private int mProgressStatus = 0; 

    private Handler mHandler = new Handler(); 

    protected void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     setContentView(R.layout.progressbar_activity); 

     mProgress = (ProgressBar) findViewById(R.id.progress_bar); 

     // Start lengthy operation in a background thread 
     new Thread(new Runnable() { 
      public void run() { 
       while (mProgressStatus < 100) { 
        mProgressStatus = doWork(); 

        // Update the progress bar 
        mHandler.post(new Runnable() { 
         public void run() { 
          mProgress.setProgress(mProgressStatus); 
         } 
        }); 
       } 
      } 
     }).start(); 
    } 
} 
+0

你不需要第二个线程,只需使用'onProgressChanged' – xdevs23

+0

好吧,只需显示你的方式.. –

+0

感谢您的回答 –

0

这里是示例代码如何使用webview客户端为此我已经使用gif imageview你可以使用progressbar代替它。

public class myWebClient extends WebViewClient { 
    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) { 

     super.onPageStarted(view, url, favicon); 
    } 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 

     ivGif.setBackgroundResource(R.drawable.anim_set_frames); 
     AnimationDrawable progressAnimation = (AnimationDrawable) ivGif.getBackground(); 
     progressAnimation.start(); 
     ivGif.setVisibility(View.VISIBLE); 
     view.loadUrl(url); 
     return true; 

    } 

    @Override 
    public void onPageFinished(WebView view, String url) { 
     super.onPageFinished(view, url); 
     ivGif.setVisibility(View.GONE); 
    } 
} 




    webViewBooking.setWebViewClient(new myWebClient()); 
    webViewBooking.getSettings().setJavaScriptEnabled(true); 
    webViewBooking.loadUrl(payment_url);