2016-02-26 71 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);